0

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?

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 2
    Does this answer your question? [CakePHP 3 DefaultPasswordHasher](https://stackoverflow.com/questions/25837332/cakephp-3-defaultpasswordhasher) – mikaelwallgren May 04 '20 at 21:07
  • 1
    TL;DR - this is expected. The default password hash uses a random salt each time. – Paul Roub May 04 '20 at 21:08

0 Answers0