如何将 sha1() 密码转换为 FOSUserBundle?

2024-03-16

我有一个遗留应用程序,可以使用以下命令对密码进行加密sha1()功能,无盐。

现在该网站正在转换为 Symfony2 和 FOSUserBundle,我如何将它们转移到新数据库?


我有同样的问题

只需像 @iamdto 所解释的那样覆盖编码器

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

你的班级应该是

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 );
    }
}

您应该添加“版本”列来获取旧用户并在下次登录时更新他们的信息

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将 sha1() 密码转换为 FOSUserBundle? 的相关文章

随机推荐