Welcome to the Cookbook

loading...

5.2.5.4 hashPasswords

hashPasswords ($data)

This method checks if the $data contains the username and password fields as specified by the variable $fields indexed by the model name as specified by $userModel. If the $data array contains both the username and password, it hashes the password field in the array and returns the data array in the same format. This function should be used prior to insert or update calls of the user when the password field is affected.

    $data['User']['username'] = 'me@me.com';
    $data['User']['password'] = 'changeme';
    $hashedPasswords = $this->Auth->hashPasswords($data);
    pr($hashedPasswords);
    /* returns:
    Array
    (
        [User] => Array
        (
            [username] => me@me.com
            [password] => 8ed3b7e8ced419a679a7df93eff22fae
        )
    )

    */
  1. $data['User']['username'] = 'me@me.com';
  2. $data['User']['password'] = 'changeme';
  3. $hashedPasswords = $this->Auth->hashPasswords($data);
  4. pr($hashedPasswords);
  5. /* returns:
  6. Array
  7. (
  8. [User] => Array
  9. (
  10. [username] => me@me.com
  11. [password] => 8ed3b7e8ced419a679a7df93eff22fae
  12. )
  13. )
  14. */

The $hashedPasswords['User']['password'] field would now be hashed using the password function of the component.

If your controller uses the Auth component and posted data contains the fields as explained above, it will automatically hash the password field using this function.