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 7625291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:10:21+00:00 2026-05-31T05:10:21+00:00

I’m actually trying to create a login form matching with my database. The form

  • 0

I’m actually trying to create a login form matching with my database.

The form works well but I’ve a problem using a UserRepository. Symfony gives me the following error:

The user provider must return a UserInterface object.
exception 'Symfony\Component\Security\Core\Exception\AuthenticationServiceException' with message 'The user provider must return a UserInterface object.' in C:\wamp\www\php\Promocast\Symfony\vendor\symfony\src\Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider.php:101

But as you can see below, my user entity is implemented by UserInterface so I really don’t understand what’s the mistake here.

My user entity:

    <?php

    namespace Promocast\UtilisateurBundle\Entity;

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

    /**
     * Promocast\UtilisateurBundle\Entity\ImUser
     * 
     * @ORM\Entity(repositoryClass="Promocast\UtilisateurBundle\Entity\ImUserRepository")
     */
    class ImUser implements UserInterface
    {

        /**
        * Here all my var and getter/setter
        * ...
        */

        /**
         * Fonctions UserInterface
         * 
         */
        public function eraseCredentials()
        {
        }
        public function getRoles()
        {
            return $this->idrole;
        }
        public function equals(UserInterface $user)
        {
            return $user->getUsername() === $this->login;
        }
        public function getUsername()
        {
            return $this->login;
        }
        public function getSalt()
        {
            return '';
        }

    }

My user repository:

    <?php

    namespace Promocast\UtilisateurBundle\Entity;

    use Symfony\Component\Security\Core\User\UserInterface;
    use Symfony\Component\Security\Core\User\UserProviderInterface;
    use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
    use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
    use Doctrine\ORM\EntityRepository;
    use Doctrine\ORM\NoResultException;

    class ImUserRepository extends EntityRepository implements UserProviderInterface
    {
        public function loadUserByUsername($login)
        {
            $user = $this->findBy(array("login" => $login));

            if (!$user) {
                throw new UsernameNotFoundException(sprintf('No user with name "%s" was found.', $login));
            }

            return $user;
        }

        public function refreshUser(UserInterface $user)
        {
            return $this->loadUserByUsername($user->getUsername());
        }

        public function supportsClass($class)
        {
            return $class === 'Promocast\UtilisateurBundle\Entity\ImUser';
        }
    }

And my security.yml:

    security:
        encoders:
            Promocast\UtilisateurBundle\Entity\ImUser: plaintext
            #Promocast\UtilisateurBundle\Security\Provider\LoginWebService: plaintext

        role_hierarchy:
            ROLE_USER_SUP:    ROLE_USER
            ROLE_ADMIN:       ROLE_USER_SUP
            ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_USER_SUP, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

        providers:
            main:
                entity: { class: PromocastUtilisateurBundle:ImUser }
                #entity: { class: Promocast\UtilisateurBundle\Entity\ImUser, property: login }
                #id: webservice_user_provider


        firewalls:
            dev:
                pattern:  ^/(_(profiler|wdt)|css|images|js)/
                security: false
            login:
                pattern:   ^/(login$|register|resetting) 
                anonymous: true                          
            main:
                pattern: ^/                      
                form_login:                      
                    login_path: /login              
                    check_path: /login_check            
                    username_parameter: _login
                    password_parameter: _password
                remember_me:
                    key:         %secret%       
                anonymous:       true           
                provider:        main
                logout:          true            
                logout:
                    path: /logout
                    target: /

        access_control:
            #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
            #- { path: ^/_internal, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 127.0.0.1 }
            #- { path: /.*, role: ROLE_USER }
            #- { path: /login, role: IS_AUTHENTICATED_ANONYMOUSLY }

Thanks a lot!

  • 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-31T05:10:22+00:00Added an answer on May 31, 2026 at 5:10 am

    It looks like your problem is here:

    public function loadUserByUsername($login)
    {
        $user = $this->findBy(array("login" => $login));
        if (!$user) {
            throw new UsernameNotFoundException(sprintf('No user with name "%s" was found.', $login));
        }
    
        return $user;
    }
    

    $this->findBy() is probably returning a cursor/resultset rather than one row as you intended (even if the resultset contains only one row).

    Try just using $this->findOneBy() instead.

    Based on your code, it looks like you are following the cookbook tutorial on How to load Security Users from the Database (the Entity Provider) – but if you’re not, that is a helpful resource in this case.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

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.