When users edit their details both field – password and password confirmation are mandatory.
It is a good idea to change it that if the user doesn’t type the password and password confirmation, the user details can be saved without having to re-enter the passwords.
To fix this issue I created the following emptyPassword() function in the User.php file:
function emptyPassword(){
if($this->data[‘User’][‘password_confirmation’] == “”){
unset($this->data[‘User’][‘password_confirmation’]);
}
}
And the rule:
’emptyPassword’ => array(
‘rule’ => array(’emptyPassword’, ‘password’),
‘on’ => ‘update’, //Only in the edit user form
But emptyPassword() function did not run since errors returning from matchPassword() function occurred first. I added ‘on’ => ‘create’ and ‘required’=>false conditions to the password array, that it runs only when creating new user, but in also did not work.
Instead matchPasswords() function I tried to use emptyPassword() function:
Again, errors that both password fields should be filled-in appears.
I decided to move forward and back to that problem in the future.