title: Symfony3 Form to change the password Error @SecurityAssert \ UserPassword
body: <p>I have a problem with the typical form to change the password in which I first put you to put your current password.</p>
  
  <p>The theory is very simple and is explained in the symfony doc but it gives me an error like the current password is incorrect</p>
  
  <p>My Model:</p>
  
  <pre><code>namespace BackendBundle\Form\Model;
  
  use Symfony\Component\Security\Core\Validator\Constraints as SecurityAssert;
  use Symfony\Component\Validator\Constraints as Assert;
  
  class ChangePassword
  {
  /**
   * @SecurityAssert\UserPassword(
   *     message = "Error al poner la contraseña actual"
   * )
   */
   protected $oldPassword;
  
  /**
   * @Assert\Length(
   *     min = 6,
   *     minMessage = "El password tiene que tener al menos 6 caracteres"
   * )
   */
   protected $password;
  
  
     /////
  public function getOldPassword() {
      return $this-&gt;oldPassword;
  }
  
  public function setOldPassword($oldPassword) {
      $this-&gt;oldPassword = $oldPassword;
  }
    /////
  public function getPassword() {
      return $this-&gt;oldPassword;
  }
  
  public function setPassword($oldPassword) {
      $this-&gt;oldPassword = $oldPassword;
  }
  }
  </code></pre>
  
  <p>The fomType:</p>
  
  <pre><code>-&gt;add('oldPassword', PasswordType::class, array(
                  'label' =&gt; 'Ponga su password actual',
                  'mapped' =&gt; false,
                  ))
  -&gt;add('password', RepeatedType::class, array(
                  "required" =&gt; "required",
                  'type' =&gt; PasswordType::class,
                  'invalid_message' =&gt; 'Los dos password deben coincidir',
                  'first_options' =&gt; array('label' =&gt; 'Password nuevo', "attr" 
  =&gt; array("class" =&gt; "form-password form-control")),
                  'second_options' =&gt; array('label' =&gt; 'Repita el Password nuevo', "attr" =&gt; array("class" =&gt; "form-password form-control"))
                      )
              )
  </code></pre>
  
  <p>​
  And little else must be done (I think) in addition to the controler create the view with the form and then collect the data of the new password, etc, but as I say, I sent error of not valid field that checks the password and I do not know if it's because the password I keep it encrypted
  My security.yml I have it as</p>
  
  <pre><code>encoders:
      BackendBundle\Entity\Users:
          algorithm: bcrypt
          cost: 6
  </code></pre>
  
  <p>My action Controller:</p>
  
  <pre><code>   public function passAction(Request $request) {
      $changePasswordModel = new ChangePassword();
      $form = $this-&gt;createForm(ChangePasswordType::class, $changePasswordModel);
  
      $form-&gt;handleRequest($request);
  
      if ($form-&gt;isSubmitted()) {
  
          if ($form-&gt;isValid()) {
  
              $user = $this-&gt;getUser(); //metemos como id la del usuario sacado de su sesion
              $encoder = $this-&gt;container-&gt;get('security.encoder_factory')-&gt;getEncoder($user);
              $password = $encoder-&gt;encodePassword($changePasswordModel-&gt;getPassword(), $user-&gt;getSalt());
              $user-&gt;setPassword($password);
              $em-&gt;persist($user);
              $flush = $em-&gt;flush();
              if ($flush === null) {
                  $this-&gt;session-&gt;getFlashBag()-&gt;add('success', 'El usuario se ha editado correctamente');
                  return $this-&gt;redirectToRoute("others_show"); //redirigimos la pagina si se incluido correctamete
              } else {
                  $this-&gt;session-&gt;getFlashBag()-&gt;add('warning', 'Error al editar el password');
              }
          } else {
              dump($form-&gt;getErrors());
              $this-&gt;session-&gt;getFlashBag()-&gt;add('warning', 'El password no se ha editado por un error en el formulario !');
          }
      }
  
      return $this-&gt;render('BackendBundle:Others:editPass.html.twig', array(
                  'form' =&gt; $form-&gt;createView(),
      ));
  }
  </code></pre>
  
  <p>It tells me that the form is not correct because the old password is incorrect. What could be wrong?</p>