How to convert sha1() passwords into FOSUserBundle?

三世轮回 提交于 2019-12-04 15:00:58

i had the same problem

just override the encoder like explained by @iamdto

# app/config/security.yml
security:
    encoders:
        FOS\UserBundle\Model\UserInterface: 
           id: your.custom.encoder

Your class should be

use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;

class CustomEncoder implements PasswordEncoderInterface
{

    public function encodePassword( $raw, $salt ) {
        //do not use salt here
        return sha1($raw);
    }

    public function isPasswordValid( $encoded, $raw, $salt ) {
        return $encoded === $this->encodePassword( $raw, $salt );
    }
}

You should add a column "version" to get legacy users and update their infos on next login

Have you tried :

# app/config/security.yml
security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha1

You should have a look at these references too :

My colleague wrote a bundle for this very purpose:

https://packagist.org/packages/markup/fallback-password-encoder-bundle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!