0

How to match new_password and confirm_password fields when they are not in database?

Hi... I would like to know how I would be able to match my fields "new_password" and "confirm_password", they are not stored in database they are just used for matching purpose in Change Password module.

I tried this but it didn't worked:

if($this->data['User']['new_password'] != $this->data['User']['confirm_password'] ) {
  $this->Session->setFlash("New password and Confirm password field do not match");
} else {
  $this->data['User']['password'] = $this->data['User']['new_password'];
  $this->data['User']['id'] = $this->User->id;

  if($this->User->save($this->data)) {
    $this->Session->setFlash("Password updated");
    $this->redirect('/users/login');
  }
}
Zbigniew
  • 27,184
  • 6
  • 59
  • 66
sachinw
  • 13
  • 2
  • What do you mean with "didn't work"? Do you get any errors? – dhofstet Jul 14 '12 at 09:36
  • Its Working fine but new_password and confirm_password matching is not taking place.... no matter if the fields are filled with the same data or not it updates the password in the backend. – sachinw Jul 14 '12 at 11:54
  • Did you check with `debug` the content of `$this->data`? – dhofstet Jul 14 '12 at 14:05

1 Answers1

0

You can try this:

// check for empty value

if( !empty( $this->data['User']['new_password'] ) && !empty( $this->data['User']['confirm_password'] ) ) {

   if( $this->data['User']['new_password'] != $this->data['User']['confirm_password']) {

       $this->Session->setFlash("New password and Confirm password field do not match");

   } else {

       $this->data['User']['password'] = $this->data['User']['new_password'];
       $this->data['User']['id'] = $this->User->id;

       if( $this->User->save($this->data) ) {

          $this->Session->setFlash("Password updated");
          $this->redirect('/users/login');

       } else {

          $this->Session->setFlash('Password update fail');

       }
   }

} else {

   $this->Session->setFlash('Enter New password and Confirm password');

}
thecodeparadox
  • 86,271
  • 21
  • 138
  • 164