null, 'cost' => 10, 'hashType' => PASSWORD_BCRYPT ); /** * Generates password hash. * * @param string $password Plain text password to hash. * @return string Password hash * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#using-bcrypt-for-passwords */ public function hash($password) { $options = array('cost' => $this->_config['cost'], 'salt' => $this->_config['salt']); $options = array_filter($options); return password_hash($password, $this->_config['hashType'], $options); } /** * Check hash. Generate hash for user provided password and check against existing hash. * * @param string $password Plain text password to hash. * @param string Existing hashed password. * @return bool True if hashes match else false. */ public function check($password, $hashedPassword) { return password_verify($password, $hashedPassword); } /** * Returns true if the password need to be rehashed, due to the password being * created with anything else than the passwords generated by this class. * * @param string $password The password to verify * @return bool */ public function needsRehash($password) { return password_needs_rehash($password, $this->_config['hashType']); } }