这个关于 Symfony 2.1 的问题
如何对用户密码进行编码:
$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);
和基本配置:
# app/config/security.yml
security:
# ...
encoders:
Acme\UserBundle\Entity\User: sha512
在 setter 模型内部:
class User implements UserInterface, \Serializable
{
public function setPassword($password)
{
$this->password = $password;
}
}
我认为加密密码的过程必须按模型处理。如何在模型中使用标准编码器工厂?