1: <?php
2: /**
3: * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
4: * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
5: *
6: * Licensed under The MIT License
7: * For full copyright and license information, please see the LICENSE.txt
8: * Redistributions of files must retain the above copyright notice.
9: *
10: * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
11: * @link https://cakephp.org CakePHP(tm) Project
12: * @since CakePHP(tm) v 2.4.0
13: * @license https://opensource.org/licenses/mit-license.php MIT License
14: */
15:
16: App::uses('AbstractPasswordHasher', 'Controller/Component/Auth');
17: App::uses('Security', 'Utility');
18:
19: /**
20: * Simple password hashing class.
21: *
22: * @package Cake.Controller.Component.Auth
23: */
24: class SimplePasswordHasher extends AbstractPasswordHasher {
25:
26: /**
27: * Config for this object.
28: *
29: * @var array
30: */
31: protected $_config = array('hashType' => null);
32:
33: /**
34: * Generates password hash.
35: *
36: * @param string $password Plain text password to hash.
37: * @return string Password hash
38: * @link https://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#hashing-passwords
39: */
40: public function hash($password) {
41: return Security::hash($password, $this->_config['hashType'], true);
42: }
43:
44: /**
45: * Check hash. Generate hash for user provided password and check against existing hash.
46: *
47: * @param string $password Plain text password to hash.
48: * @param string $hashedPassword Existing hashed password.
49: * @return bool True if hashes match else false.
50: */
51: public function check($password, $hashedPassword) {
52: return $hashedPassword === $this->hash($password);
53: }
54:
55: }
56: