I\'m moving from expressionengine to symfony2 and I\'m looking for the best way to migrate the user passwords. The goal is to let legacy users log in with their existing cre
Figured it out!
Create a custom encoder and use FOSAdvancedEncoder bundle to select the appropriate encoder.
1. Create the encoder
encodePassword($raw, $salt);
}
}
2. Register your encoder as service
services:
acme.legacy_encoder:
class: Acme\MyBundle\Security\Encoder\LegacyEncoder
3. Install FOSAdvancedEncoderBundle
Look here: https://github.com/friendsofsymfony/FOSAdvancedEncoderBundle/blob/master/Resources/doc/index.md
4. Configure your encoders
In app/config.yml
:
fos_advanced_encoder:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
legacy_encoder:
id: acme.legacy_encoder
5. Implement the encoder aware interface in your User Class
use FOS\AdvancedEncoderBundle\Security\Encoder\EncoderAwareInterface;
use FOS\UserBundle\Entity\User as BaseUser;
class User extends BaseUser implements EncoderAwareInterface {
...
public function getEncoderName() {
if($this->islegacy()) {
return "legacy_encoder";
}
return NULL;
}
}
Remember to add a boolean field to administer if a user is a legacy user or not.
That's it.