I'm following the cakePHP4 Blog Tutorial and had a problem with the _setPassword()
. Every time I try to edit the user using the same password I got a different hash.
This is my setPassword function:
protected function _setPassword(string $password) : ?string {
$hasher = new DefaultPasswordHasher();
// return '123456';
return $hasher->hash('123456');
}
I force the $password
value to be sure of the value. And this is my UsersControles edit function:
public function edit($id = null)
{
$this->request->allowMethod(['patch','post', 'put']);
$user = $this->Users->get($id);
$data= $this->request->getData();
$user = $this->Users->patchEntity($user,$data);
if ($this->Users->save($user)) {
$message = 'Saved';
} else {
$message = 'Error';
}
$this->set([
'message' => $message,
'user' => $user,
]);
$this->viewBuilder()->setOption('serialize', ['user', 'message']);
}
Does anyone know where I'm going wrong?