note 119576 deleted from function.hash-equals by cmb
| From: | cmb@php.net | Date: | Thu, 29 Jul 2021 12:42:17 +0000 |
| Subject: | note 119576 deleted from function.hash-equals by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-216685@lists.php.net to get a copy of this message | ||
Note Submitter: s rotondo90 at gmail com
----
asphp has done a great job and that one of Markus P. N. is also good too.
However i made my own more concise version of the asphp code that supports different lenght strings
and i used the same tests of Markus in order see how it works.
<?php
if(!function_exists('hash_equals')) {
function hash_equals($known_string, $user_string) {
$ret = 0;
if (strlen($known_string) !== strlen($user_string)) {
$user_string = $known_string;
$ret = 1;
}
$res = $known_string ^ $user_string;
for ($i = strlen($res) - 1; $i >= 0; --$i) {
$ret |= ord($res[$i]);
}
return !$ret;
}
}
?>