Skip to content

Commit

Permalink
Use PHP hash_equals() to compare the token
Browse files Browse the repository at this point in the history
This avoids a possible timing attack.
hash_equals() was introduced in PHP 5.6.
  • Loading branch information
fscoto committed Jun 23, 2024
1 parent a113d63 commit 84e01ea
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Totp.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public static function verify(
$stepEnd = $currentStep + (int)$acceptStepFuture + 1;
for ($testTimeStep = $stepBegin; $testTimeStep < $stepEnd; ++$testTimeStep) {
$testValue = self::calcMain($keyBinary, $testTimeStep, $digits, $hash);
if ($testValue === $value) {
if (hash_equals($testValue, $value)) {
return true;
}
}
Expand Down

0 comments on commit 84e01ea

Please sign in to comment.