password decode in controller
symfony
Solution
You should encrypt the same way the old password was, the password entered by user. The result encrypted password should be the same.
$encoder = new MessageDigestPasswordEncoder('sha1');
$password = $encoder->encodePassword($editForm->get('antigua')->getData(), $entity->getSalt());
Now you can compare the old encrypted password with the new user entered one...
Problem
I use it to encode my password: ``` $entity->setSalt(md5(time())); $encoder = new MessageDigestPasswordEncoder('sha1'); $password = $encoder->encodePassword($editForm->get('password')->getData(), $entity->getSalt()); $entity->setPassword($password); ``` But how could relizar step opposite? that is, how could I get the unencrypted password? if i use this ``` $entity->getPassword() ``` shows me this: ``` xOGjEeMdi4nwanOustbbJlDkug8= ``` Thank you very much for the reply. I am trying to create a form where users enter the old password and verify that it is true. in the form I have this: ``` ->add('antigua', 'password', array('property_path' => false)) ->add('password', 'repeated', array('first_name' => 'Nueva contraseña','second_name' => 'Repite contraseña','type' => 'password')); ``` and when I go to edit a user in the crud I have this: in update action : ``` 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(), ); } ``` the problem is I can not get the encoded password is blank. (in db is correct) thanks