@@ -19,22 +19,21 @@ class Password
1919 *
2020 * @var int
2121 */
22- protected static $ rounds = 12 ;
22+ protected static $ rounds = 10 ;
2323
2424 /**
2525 * Returns the hashing type for a specified password hash.
2626 *
2727 * Automatically detects the hash type: "sha1" (for UserCake legacy accounts), "legacy" (for 0.1.x accounts), and "modern" (used for new accounts).
2828 * @param string $password the hashed password.
29- * @param array $options
3029 * @return string "sha1"|"legacy"|"modern".
3130 */
32- public static function getHashType ($ password, array $ options = [] )
31+ public static function getHashType ($ password )
3332 {
3433 // If the password in the db is 65 characters long, we have an sha1-hashed password.
3534 if (strlen ($ password ) == 65 ) {
3635 return 'sha1 ' ;
37- } elseif (substr ($ password, 0 , 7 ) == ' $2y$ ' . static :: cost ( $ options ) . ' $ ' ) {
36+ } elseif (strlen ($ password ) == 82 ) {
3837 return 'legacy ' ;
3938 }
4039
@@ -67,33 +66,29 @@ public static function hash($password, array $options = [])
6766 *
6867 * @param string $password The plaintext password to verify.
6968 * @param string $hash The hash to compare against.
69+ * @param array $options
7070 * @return boolean True if the password matches, false otherwise.
7171 */
7272 public static function verify ($ password , $ hash , array $ options = [])
7373 {
74- $ hashType = static ::getHashType ($ hash, $ options );
74+ $ hashType = static ::getHashType ($ hash );
7575
7676 if ($ hashType == 'sha1 ' ) {
7777 // Legacy UserCake passwords
7878 $ salt = substr ($ hash , 0 , 25 ); // Extract the salt from the hash
79- $ hashInput = $ salt . sha1 ($ salt . $ password );
80- if (hash_equals ($ hashInput , $ hash ) === true ) {
81- return true ;
82- }
79+ $ inputHash = $ salt . sha1 ($ salt . $ password );
8380
84- return false ;
81+ return ( hash_equals ( $ inputHash , $ hash ) === true ) ;
8582
8683 } elseif ($ hashType == 'legacy ' ) {
8784 // Homegrown implementation (assuming that current install has been using a cost parameter of 12)
8885 // Used for manual implementation of bcrypt.
89- $ extract = substr ($ hash , 0 , 60 );
90- $ compare = crypt ($ password , '$2y$ ' . static ::cost ($ options ) . '$ ' . substr ($ hash , 60 ));
91-
92- if (hash_equals ($ extract , $ compare ) === true ) {
93- return true ;
94- }
86+ // Note that this legacy hashing put the salt at the _end_ for some reason.
87+ $ salt = substr ($ hash , 60 );
88+ $ inputHash = crypt ($ password , '$2y$12$ ' . $ salt );
89+ $ correctHash = substr ($ hash , 0 , 60 );
9590
96- return false ;
91+ return ( hash_equals ( $ inputHash , $ correctHash ) === true ) ;
9792 }
9893
9994 // Modern implementation
0 commit comments