How to convert sha1() passwords into FOSUserBundle?

旧巷老猫 提交于 2019-12-21 21:13:13

问题


I have legacy application that keeps passwords encrypted with sha1() function, no salt.

Now that site is being converted into Symfony2 and FOSUserBundle, how can I transfer them to new database?


回答1:


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




回答2:


Have you tried :

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

You should have a look at these references too :

  • Configure your application's security.yml
  • Encoding the User's Password



回答3:


My colleague wrote a bundle for this very purpose:

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



来源:https://stackoverflow.com/questions/14435820/how-to-convert-sha1-passwords-into-fosuserbundle

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