55 * @link https://github.com/userfrosting/UserFrosting
66 * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
77 */
8- namespace UserFrosting \Sprinkle \Account \Util ;
8+ namespace UserFrosting \Sprinkle \Account \Authenticate ;
99
1010/**
11- * Password utility class
11+ * Password hashing and validation class
1212 *
1313 * @author Alex Weissman (https://alexanderweissman.com)
1414 */
15- class Password
15+ class Hasher
1616{
1717 /**
1818 * Default crypt cost factor.
1919 *
2020 * @var int
2121 */
22- protected static $ rounds = 10 ;
22+ protected $ defaultRounds = 10 ;
2323
2424 /**
2525 * Returns the hashing type for a specified password hash.
@@ -28,7 +28,7 @@ class Password
2828 * @param string $password the hashed password.
2929 * @return string "sha1"|"legacy"|"modern".
3030 */
31- public static function getHashType ($ password )
31+ public function getHashType ($ password )
3232 {
3333 // If the password in the db is 65 characters long, we have an sha1-hashed password.
3434 if (strlen ($ password ) == 65 ) {
@@ -48,10 +48,10 @@ public static function getHashType($password)
4848 * @return string the hashed password.
4949 * @throws HashFailedException
5050 */
51- public static function hash ($ password , array $ options = [])
51+ public function hash ($ password , array $ options = [])
5252 {
5353 $ hash = password_hash ($ password , PASSWORD_BCRYPT , [
54- 'cost ' => static :: cost ($ options ),
54+ 'cost ' => $ this -> cost ($ options ),
5555 ]);
5656
5757 if (!$ hash ) {
@@ -69,9 +69,9 @@ public static function hash($password, array $options = [])
6969 * @param array $options
7070 * @return boolean True if the password matches, false otherwise.
7171 */
72- public static function verify ($ password , $ hash , array $ options = [])
72+ public function verify ($ password , $ hash , array $ options = [])
7373 {
74- $ hashType = static :: getHashType ($ hash );
74+ $ hashType = $ this -> getHashType ($ hash );
7575
7676 if ($ hashType == 'sha1 ' ) {
7777 // Legacy UserCake passwords
@@ -101,8 +101,8 @@ public static function verify($password, $hash, array $options = [])
101101 * @param array $options
102102 * @return int
103103 */
104- protected static function cost (array $ options = [])
104+ protected function cost (array $ options = [])
105105 {
106- return isset ($ options ['rounds ' ]) ? $ options ['rounds ' ] : static :: $ rounds ;
106+ return isset ($ options ['rounds ' ]) ? $ options ['rounds ' ] : $ this -> defaultRounds ;
107107 }
108108}
0 commit comments