This question about Symfony 2.1
How can I encode 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 base config:
# app/config/security.yml
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 process of encryption password must deal by model. How can I use standart encoder factory inside the model?
The entity contains data, not handles it. If you want to change data of an entity you can create the event listener and do stuff before persistence. Check How to Register Event Listeners and Subscribers from the official documentation.
You can also take a look at FosUserBundle and its user management.
So, the main idea is to pass plain password from a form to the user entity and encode it before persitence using event listener.