This question is about Symfony 2.1
How can I encode a user password with:
$factory = $this->get('security.encoder_factory');
$user = new Acme\UserBundle\Entity\User();
$encoder = $factory->getEncoder($user);
$password = $encoder->encodePassword('ryanpass', $user->getSalt());
$user->setPassword($password);
And the basic configuration:
security:
encoders:
Acme\UserBundle\Entity\User: sha512
Inside the setter models:
class User implements UserInterface, \Serializable
{
public function setPassword($password)
{
$this->password = $password;
}
}
I believe that the password encryption process should follow the model. How can I use a standard factory encoder inside a model?
Stmol source
share