Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony2 and symfony1 application same password encryption

I have a symfony1 application with sfGuardUser plugin. I need to use the same database in my new symfony2 application.

How should I define the password encoder so it match the symfony1 encoded passwords?

like image 925
brpaz Avatar asked Dec 05 '25 14:12

brpaz


1 Answers

If you didn't provide a different encoding algorithm back then Symfony 1.x would use sha1($salt.$rawPassword). So your PasswordEncoder should look like this:

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

class PasswordEncoder implements PasswordEncoderInterface
{
    public function encodePassword($raw, $salt)
    {
        return sha1($salt.$raw);
    }

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

Good luck!

like image 184
flu Avatar answered Dec 07 '25 03:12

flu