我用它来编码我的密码:
$entity->setSalt(md5(time()));
$encoder = new MessageDigestPasswordEncoder('sha1');
$password = $encoder->encodePassword($editForm->get('password')->getData(), $entity->getSalt());
$entity->setPassword($password);
Run Code Online (Sandbox Code Playgroud)
但是如何才能重新开始呢?也就是说,我怎么能得到未加密的密码?如果我使用这个
$entity->getPassword()
Run Code Online (Sandbox Code Playgroud)
告诉我这个:
xOGjEeMdi4nwanOustbbJlDkug8=
Run Code Online (Sandbox Code Playgroud)
非常感谢你的答复.我正在尝试创建一个表单,用户输入旧密码并验证它是否为真.我有这样的形式:
->add('antigua', 'password', array('property_path' => false))
->add('password', 'repeated', array('first_name' => 'Nueva contraseña','second_name' => 'Repite contraseña','type' => 'password'));
Run Code Online (Sandbox Code Playgroud)
当我在crud中编辑用户时,我有:在更新操作中:
public function updateAction($id)
{
$em = $this->getDoctrine()->getEntityManager();
$entity = $em->getRepository('miomioBundle:Empleado')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Empleado entity.');
}
$editForm = $this->createForm(new EmpleadoType(), $entity);
$deleteForm = $this->createDeleteForm($id);
$request = $this->getRequest();
**$entity->getPassword() is blank why?**
$editForm->bindRequest($request);
if ($editForm->isValid()){
$em->persist($entity);
$em->flush();
}
return $this->redirect($this->generateUrl('empleado_edit', array('id' => $id)));
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
Run Code Online (Sandbox Code Playgroud)
问题是我无法获得编码密码为空.(在db中是正确的)谢谢
不可能解密以 sha1 或 md5 编码的密码,这些 crypt 方法被创建为不可能被解密!
自定义编码器:
唯一的方法是使用自制方法创建您自己的自定义编码器来加密(并解密)您的密码,这里有一个示例: http: //blogsh.de/2011/09/29/create-a-custom-password -symfony 编码器/
您不必在encodePassword()中使用$salt,例如您可以将每个字母替换为特定的数字,以便您可以通过执行相反的操作来检索密码,您也可以削减盐并在密码中添加部分, ETC...
纯文本,不推荐:
或者不太推荐,不要加密您的密码并让它们为明文:
# app/config/security.yml
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9435 次 |
| 最近记录: |