title: cakephp3- hashed password doesnt match when compared
body: <p>CakePHP version: 3.3.5 </p>
  
  <p>I'm building a simple system using which users can login (using a email and password) and after login they can change their password.</p>
  
  <p>For this, I'm using <code>DefaultPasswordHasher</code></p>
  
  <p>I had a few users already in my db. Their record were already present. So when I did the login function, it worked. I compared the password the user enters with the hased password already present in the db. The check was successful and user was able to login.</p>
  
  <p>Now after login, I wrote change password function, which updated the user password. New hash string replaced the old password string but when I try to login again, login fails.</p>
  
  <p>I will share my controller here. It's pretty basic.</p>
  
  <pre><code>namespace Api\Controller;
  use Cake\Utility\Security;
  use Cake\Utility\Hash;
  use Cake\Auth\DefaultPasswordHasher;
  use Api\Controller\AppController;
  
  class LoginController extends AppController
  {
      public function initialize()
      {
          parent::initialize();
          $this-&gt;loadComponent('RequestHandler');
      }
  
      //Function to reset the password
      public function resetPassword()
      {
          $pass   = $this-&gt;request-&gt;data['pass'];
          $hasher = new DefaultPasswordHasher();
          $hashedPass = $hasher-&gt;hash($pass);
  
          $this-&gt;loadModel('Login');
          //save it to db
          $responseArray      = $this-&gt;Login-&gt;resetPassword($hashedPass); 
          $this-&gt;set(compact('responseArray'));
          $this-&gt;set('_serialize', ['responseArray']);
      }
  
       //Function to login
       public function login()
       {
          if ($this-&gt;request-&gt;is('post')) 
          {
              //Password submitted via form
              $pass   = $this-&gt;request-&gt;data['pass'];
  
              //Hashed password fetched from db via a function call
              $actualPassword = 'hashedPasswordString'
  
              //Compare password submitted and hash from db
              if($this-&gt;checkPassword($pass,$actualPassword))
              {
                  $result = 'password matched';
              }
              else
              {
                  $result = 'password doesnot match';
              }
          }
          $this-&gt;set(compact('result'));
          $this-&gt;set('_serialize', ['result']);       
       }
  
      //Function to compare password and hash
      public function checkPassword($passedPassword , $actualPassword) 
      {
          if ((new DefaultPasswordHasher)-&gt;check($passedPassword, $actualPassword)) {
              return true;
          } else {
              return false;
          }
      }
  
  }
  </code></pre>
  
  <p>Can anyone tell me why the passwords don't match. I'm new to CakePHP framework. Thanks in advance!</p>