This repository was archived by the owner on May 31, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -38,10 +38,6 @@ private function __construct()
38
38
*/
39
39
public static function equals ($ knownString , $ userInput )
40
40
{
41
- if (function_exists ('hash_equals ' )) {
42
- return hash_equals ($ knownString , $ userInput );
43
- }
44
-
45
41
// Avoid making unnecessary duplications of secret data
46
42
if (!is_string ($ knownString )) {
47
43
$ knownString = (string ) $ knownString ;
@@ -51,16 +47,20 @@ public static function equals($knownString, $userInput)
51
47
$ userInput = (string ) $ userInput ;
52
48
}
53
49
50
+ if (function_exists ('hash_equals ' )) {
51
+ return hash_equals ($ knownString , $ userInput );
52
+ }
53
+
54
54
$ knownLen = self ::safeStrlen ($ knownString );
55
55
$ userLen = self ::safeStrlen ($ userInput );
56
56
57
- // Set the result to the difference between the lengths
58
- $ result = $ knownLen - $ userLen ;
57
+ if ($ userLen != $ knownLen ) {
58
+ return false ;
59
+ }
59
60
60
- // Always iterate over the minimum length possible.
61
- $ iterationLen = min ($ knownLen , $ userLen );
61
+ $ result = 0 ;
62
62
63
- for ($ i = 0 ; $ i < $ iterationLen ; $ i ++) {
63
+ for ($ i = 0 ; $ i < $ knownLen ; $ i ++) {
64
64
$ result |= (ord ($ knownString [$ i ]) ^ ord ($ userInput [$ i ]));
65
65
}
66
66
You can’t perform that action at this time.
0 commit comments