Symfony2 custom Password Encoder (bcrypt)

前端 未结 3 593
谎友^
谎友^ 2021-02-05 19:49

I\'ve written my own password encoder which implements the PasswordEncoderInterface:

class BCryptPasswordEncoder implements PasswordEncoderInterface         


        
3条回答
  •  广开言路
    2021-02-05 20:11

    Your encoders section should look like this:

    encoders:
        Acme\UserBundle\Entity\User:
            id: bcrypt.password.encoder
    

    where Acme\UserBundle is your vendor and bundle namespace, of course.

    For reference, a complete example security config can be found here.

    EDIT: The way the encoder factory works (source code here, relevant lines start on line 33) is that in your config, you have given the framework a class, and an encoder to use for the class. It's Doctrine-independent, so just provide the fully-qualified class name of your user object in the config instead of a "user entity," and when your password is encoded, Symfony will know how to handle it.

提交回复
热议问题