14

i would like to create a new user in FOSUserBundle (Symfony2), but i always get the same message (i'm using php app/console fos:user:create ) :

No encoder has been configured for account "MyProject\UserBundle\Entity\User".

the imports are in the right order

public function registerBundles()
{
    $bundles = array(
        //...
        new MyProject\UserBundle\MyProjectUserBundle(),
        new FOS\UserBundle\FOSUserBundle(),
    );

the security file :

security:
    encoders:
        Symfony\Component\Security\Core\User\User: plaintext

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

but i'm always getting the same error... Do you know how to fix this? The solution here is not working for me

Thanks

Community
  • 1
  • 1
Paul
  • 6,108
  • 14
  • 72
  • 128

3 Answers3

41

You are missing your own user's class in the encoders configuration, for example:

security:
    encoders:
        Symfony\Component\Security\Core\User\User: plaintext
        MyProject\UserBundle\Entity\User: sha512

Alternatively you can match it on the FOSUserBundle interface like so:

security:
    encoders:
        Symfony\Component\Security\Core\User\User: plaintext
        FOS\UserBundle\Model\UserInterface: sha512
Seldaek
  • 40,986
  • 9
  • 97
  • 77
  • thanks ! it works, i also had to use `php -c` then the path to usr > private > php.ini with `date.timezone` and finally create the user. Thanks Seldaek! – Paul Mar 09 '12 at 15:52
3

For Symfony 2.7+ you should use this configuration:

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

BUT! you also should have PHP 5.5 and Apache 2.4 or Nginx.

LaurentG
  • 474
  • 4
  • 16
D.Dimitrioglo
  • 3,413
  • 2
  • 21
  • 41
0

edit security.yml in app/config

security:
    encoders:
        AppBundle\Entity\User: bcrypt

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

under main add "logout: ~" as well

For Symfony 4.x see https://youtu.be/QgYQWGwY9tM

Robert Saylor
  • 1,279
  • 9
  • 11