Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7587985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:48:40+00:00 2026-05-30T19:48:40+00:00

I have recently started setting up the security for my Symfony2 project. I opted

  • 0

I have recently started setting up the security for my Symfony2 project. I opted to encode with sha256 using a salt. When I tried to login with a sample account in the database (with self-calculated sha256 salt/hash), it kept failing without giving me any error messages and I could not figure out why.
I decided to put some simple code in the loginAction() method of my Controller. This is the method that Symfony2 calls when a user fails to login using the specified form. I entered the following code:

$factory = $this->get('security.encoder_factory');
$em = $this->container->get('doctrine')->getEntityManager();
$userRep = $em->getRepository('MyProjectMyBundle:Users');
$user = $userRep->find(2);

$encoder = $factory->getEncoder($user);
$password = $encoder->encodePassword('cookie', 'thisisasalt');
$user->setPassword($password);
print($password);

However, when I tried to login, Symfony2 gave me the following error:

Catchable Fatal Error: Argument 1 passed to Symfony\Component\Security\Core\Encoder\EncoderFactory::getEncoder() must be an instance of Symfony\Component\Security\Core\User\UserInterface, instance of MyProject\MyBundle\Entity\Users given, called in /var/www/Symfony/src/MyProject/MyBundle/Controller/MainController.php on line 35 and defined in /var/www/Symfony/vendor/symfony/src/Symfony/Component/Security/Core/Encoder/EncoderFactory.php line 33

So basically, it’s saying that the argument of getEncoder() must be an instance of Symfony\Component\Security\Core\User\UserInterface. However, when I inspect MyProject\MyBundle\Entity\Users.php, it starts with the following lines:

<?php
namespace MyProject\MyBundle\Entity;

use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\ORM\Mapping as ORM;

...

So the Users class actually implements the UserInterface class. It contains all the functions in UserInterface class. I have created all these files in the way the Symfony2 tutorial told me to. What is the reason Symfony2 doesn’t recognize my Users instance as an UserInterface instance?

P.S.: The database was created by someone else, I just have to work with it. The Users table contains many more information than just that required by UserInterface.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:48:42+00:00Added an answer on May 30, 2026 at 7:48 pm

    Nevermind, I am an idiot.

    I forgot that, in addition to including the UserInterface class, you also have to make sure your class implements the UserInterface.

    I changed it to this:

    class Users implements UserInterface
    

    It now works perfectly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently started using Vim as my text editor and am currently working
I have recently started working on a very large C++ project that, after completing
I have recently started using DocCheck for checking the validity of JavaDoc's in code
I've recently started using Gradle and replacing my existing Maven-based projects. I have had
I have a project that I have recently started working on seriously but had
I have recently started using ASP.Net MVC 3 RC 2 and have attempted to
I have recently started to use Eclipse after using IntelliJ for a few years.
I've recently started work on a new project using EpiServer which I am totally
I have recently started having problems with TortoiseCVS, or more specifically with plink, the
I have recently started looking into Google Charts API for possible use within the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.