0
我在security.yml此行:索纳塔管理prepersist编码密码
安全:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
m_and_m\UsuariosBundle\Entity\Usuario: { algorithm: sha512, iterations: 10 }
在我UsuariosAdmin.php我formmapper:
$formMapper
->add('nombre')
->add('email','email')
->add('password', 'repeated', array(
'type' => 'password',
'options' => array('translation_domain' => 'FOSUserBundle'),
'first_options' => array('label' => 'form.password'),
'second_options' => array('label' => 'form.password_confirmation'),
'invalid_message' => 'fos_user.password.mismatch',
))
;
在这个文件中,在我的预处理方法中,我这样做是为了enco de密码到sha512:
public function prePersist($object)
{
$container = $this->getConfigurationPool()->getContainer();
$entityManager = $container->get('doctrine.orm.entity_manager');
$password=$object->getPassword();
$password=hash('sha512',$password);
$object->setPassword($password);
$entityManager->persist($object);
$entityManager->flush();
}
但我想知道如何调用security.yml的编码器,而不是手动编码密码。
我试过这个解决方案,但没有工作。使用此代码,应用程序将返回错误500.我也尝试获取m_and_m \ UsuariosBundle \ Entity \ Usuario的密码编码器。我使用$ user = new m_and_m \ UsuariosBundle \ Entity \ Usuarios();但它试图找到它的路线是:m_and_m \ UsuariosBundle \ Admin \ m_and_m \ UsuariosBundle \ Entity,并且此路线的实际路线是m_and_m \ UsuariosBundle \ Entity \ Usuarios。 – SensacionRC