gpt4 book ai didi

symfony - Controller 中的密码解码

转载 作者:行者123 更新时间:2023-12-04 18:01:55 25 4
gpt4 key购买 nike

我用它来编码我的密码:

 $entity->setSalt(md5(time()));
$encoder = new MessageDigestPasswordEncoder('sha1');
$password = $encoder->encodePassword($editForm->get('password')->getData(), $entity->getSalt());
$entity->setPassword($password);

但是relizar怎么会反其道而行之呢?也就是说,我怎么能得到未加密的密码?如果我用这个
$entity->getPassword()

给我看这个:
xOGjEeMdi4nwanOustbbJlDkug8=

非常感谢你的答复。我正在尝试创建一个表单,用户可以在其中输入旧密码并验证它是否正确。以我的形式:
            ->add('antigua', 'password', array('property_path' => false))
->add('password', 'repeated', array('first_name' => 'Nueva contraseña','second_name' => 'Repite contraseña','type' => 'password'));

当我在 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(),
);
}

问题是我无法得到编码密码为空。 (在 db 中是正确的)
谢谢

最佳答案

您应该以与旧密码相同的方式加密,即用户输入的密码。结果加密的密码应该是一样的。

$encoder = new MessageDigestPasswordEncoder('sha1');
$password = $encoder->encodePassword($editForm->get('antigua')->getData(), $entity->getSalt());

现在您可以将旧的加密密码与新用户输入的密码进行比较...

关于symfony - Controller 中的密码解码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13100829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com