pictcode / lib / Cake / Controller / Component / Auth / BlowfishPasswordHasher.php @ 19966135
履歴 | 表示 | アノテート | ダウンロード (1.57 KB)
| 1 | 635eef61 | spyder1211 | <?php
 | 
      
|---|---|---|---|
| 2 | /**
 | 
      ||
| 3 |  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 | 
      ||
| 4 |  * Copyright (c) Cake Software Foundation, Inc. (http://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. (http://cakefoundation.org)
 | 
      ||
| 11 |  * @link          http://cakephp.org CakePHP(tm) Project
 | 
      ||
| 12 |  * @since         CakePHP(tm) v 2.4.0
 | 
      ||
| 13 |  * @license       http://www.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 |  * Blowfish password hashing class.
 | 
      ||
| 21 |  *
 | 
      ||
| 22 |  * @package       Cake.Controller.Component.Auth
 | 
      ||
| 23 |  */
 | 
      ||
| 24 | class BlowfishPasswordHasher extends AbstractPasswordHasher {  | 
      ||
| 25 | |||
| 26 | /**
 | 
      ||
| 27 |  * Generates password hash.
 | 
      ||
| 28 |  *
 | 
      ||
| 29 |  * @param string $password Plain text password to hash.
 | 
      ||
| 30 |  * @return string Password hash
 | 
      ||
| 31 |  * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#using-bcrypt-for-passwords
 | 
      ||
| 32 |  */
 | 
      ||
| 33 | public function hash($password) {  | 
      ||
| 34 | return Security::hash($password, 'blowfish', false);  | 
      ||
| 35 | }  | 
      ||
| 36 | |||
| 37 | /**
 | 
      ||
| 38 |  * Check hash. Generate hash for user provided password and check against existing hash.
 | 
      ||
| 39 |  *
 | 
      ||
| 40 |  * @param string $password Plain text password to hash.
 | 
      ||
| 41 |  * @param string $hashedPassword Existing hashed password.
 | 
      ||
| 42 |  * @return bool True if hashes match else false.
 | 
      ||
| 43 |  */
 | 
      ||
| 44 | public function check($password, $hashedPassword) {  | 
      ||
| 45 | return $hashedPassword === Security::hash($password, 'blowfish', $hashedPassword);  | 
      ||
| 46 | }  | 
      ||
| 47 | |||
| 48 | }  |