From 7cabb4e4d53141d1e5c7b7c523ecc47e72878abf Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 21 Sep 2011 07:38:22 -0400 Subject: [PATCH] Extracting password hashing into as separate method. This makes is much easier for a subclass to only change how passwords are hashed. --- .../Controller/Component/Auth/BaseAuthenticate.php | 13 ++++++++++++- .../Controller/Component/Auth/FormAuthenticate.php | 2 +- lib/Cake/Controller/Component/AuthComponent.php | 3 +++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Controller/Component/Auth/BaseAuthenticate.php b/lib/Cake/Controller/Component/Auth/BaseAuthenticate.php index 7fa44e7cd..4d2b73138 100644 --- a/lib/Cake/Controller/Component/Auth/BaseAuthenticate.php +++ b/lib/Cake/Controller/Component/Auth/BaseAuthenticate.php @@ -73,7 +73,7 @@ abstract class BaseAuthenticate { $conditions = array( $model . '.' . $fields['username'] => $username, - $model . '.' . $fields['password'] => AuthComponent::password($password), + $model . '.' . $fields['password'] => $this->_password($password), ); if (!empty($this->settings['scope'])) { $conditions = array_merge($conditions, $this->settings['scope']); @@ -89,6 +89,17 @@ abstract class BaseAuthenticate { return $result[$model]; } +/** + * Hash the plain text password so that it matches the hashed/encrytped password + * in the datasource. + * + * @param string $password The plain text password. + * @return string The hashed form of the password. + */ + protected function _password($password) { + return Security::hash($password, null, true); + } + /** * Authenticate a user based on the request information. * diff --git a/lib/Cake/Controller/Component/Auth/FormAuthenticate.php b/lib/Cake/Controller/Component/Auth/FormAuthenticate.php index 833b4d687..174287e19 100644 --- a/lib/Cake/Controller/Component/Auth/FormAuthenticate.php +++ b/lib/Cake/Controller/Component/Auth/FormAuthenticate.php @@ -65,4 +65,4 @@ class FormAuthenticate extends BaseAuthenticate { ); } -} \ No newline at end of file +} diff --git a/lib/Cake/Controller/Component/AuthComponent.php b/lib/Cake/Controller/Component/AuthComponent.php index deef4bc71..cbc72501e 100644 --- a/lib/Cake/Controller/Component/AuthComponent.php +++ b/lib/Cake/Controller/Component/AuthComponent.php @@ -661,6 +661,9 @@ class AuthComponent extends Component { /** * Hash a password with the application's salt value (as defined with Configure::write('Security.salt'); * + * This method is intended as a convenience wrapper for Security::hash(). If you want to use + * a hashing/encryption system not supported by that method, do not use this method. + * * @param string $password Password to hash * @return string Hashed password * @link http://book.cakephp.org/view/1263/password