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