Password updated empty when i edit with empty password field?

I am using this code to validate in cakephp3.

> $validator
>                 ->requirePresence('password', 'create')
>                 ->add('password', 'match', ['rule' => ['compareWith', 'confirm_password'], 'message' => __('Password and Confirm Password should be same')])
>                 ->allowEmpty('password', 'update');

When i create new user, password field is validated. But i edit that user, i am not change password, it save empty in DB.
I wont change password until password field is change.

How i fix it?


Because in the validation you allow the password to be empty.
You should filter it in a setter, like this

// src/Model/Entity/User.php
protected function _setPassword($value)
    if ($value !== '') {
        $hasher = new DefaultPasswordHasher();

        return $hasher->hash($value);
    } else {
        return $this->password;

thanks for you reply…:+1: