@@ -17,6 +17,10 @@ class SecurePassword extends HashAlgorithm
1717 */
1818 public function __construct ()
1919 {
20+ if (empty ($ this ->algo )) {
21+ $ this ->algo = self ::DEFAULT ;
22+ }
23+
2024 $ this ->setPepper ();
2125 }
2226
@@ -52,10 +56,6 @@ public function getPepper(): string
5256 */
5357 public function createHash (string $ password , bool $ info = false )
5458 {
55- if (empty ($ this ->algo )) {
56- $ this ->algo = self ::DEFAULT ;
57- }
58-
5959 $ pwd_peppered = $ this ->passwordPeppered ($ password );
6060 $ pwd_hashed = password_hash ($ pwd_peppered , $ this ->algo , $ this ->options );
6161
@@ -73,32 +73,25 @@ public function createHash(string $password, bool $info = false)
7373 *
7474 * @param string $password
7575 * @param string $hash
76- * @param bool $verify_needs_rehash
7776 *
7877 * @return mixed
7978 */
80- public function verifyHash (string $ password , $ hash, bool $ verify_needs_rehash = false )
79+ public function verifyHash (string $ password , $ hash )
8180 {
8281 if (is_array ($ hash )) {
8382 throw new HashException ("You are returning the hash information. Enter 'false' in the 'createHash' method " );
8483 }
8584
86- if (empty ($ this ->algo )) {
87- $ this ->algo = self ::DEFAULT ;
88- }
89-
9085 $ pph_strt = microtime (true );
9186 $ pwd_peppered = $ this ->passwordPeppered ($ password );
9287
9388 if (password_verify ($ pwd_peppered , $ hash )) {
9489 try {
95- return $ this -> needsRehash ( $ password , $ hash , $ verify_needs_rehash ) ;
90+ return true ;
9691 } finally {
9792 $ end = (microtime (true ) - $ pph_strt );
9893 $ wait = bcmul ((1 - $ end ), 1000000 ); // usleep(250000) 1/4 of a second
9994 usleep ($ wait );
100-
101- #echo "<br>Execution time:" . (microtime(true) - $pph_strt) . "; ";
10295 }
10396 } else {
10497 return false ;
@@ -133,22 +126,17 @@ public function getOptimalBcryptCost(int $min_ms = 250, string $password = "test
133126 *
134127 * @param string $password
135128 * @param string $hash
136- * @param bool $verify
137129 *
138130 * @return mixed
139131 */
140- private function needsRehash (string $ password , string $ hash, bool $ verify )
132+ public function needsRehash (string $ password , string $ hash )
141133 {
142- if ($ verify == true ) {
143- if (password_needs_rehash ($ hash , $ this ->algo )) {
144- $ newHash = $ this ->createHash ($ password );
134+ if (password_needs_rehash ($ hash , $ this ->algo )) {
135+ $ newHash = $ this ->createHash ($ password );
145136
146- return $ newHash ;
147- } else {
148- return true ;
149- }
137+ return $ newHash ;
150138 } else {
151- return true ;
139+ return false ;
152140 }
153141 }
154142
0 commit comments