Cheetah
polyfills.php
Go to the documentation of this file.
1 <?php
28 if (!function_exists('hash_equals')) {
29  function hash_equals($knownString, $userString)
30  {
31  if (function_exists('mb_strlen')) {
32  $kLen = mb_strlen($knownString, '8bit');
33  $uLen = mb_strlen($userString, '8bit');
34  } else {
35  $kLen = strlen($knownString);
36  $uLen = strlen($userString);
37  }
38  if ($kLen !== $uLen) {
39  return false;
40  }
41  $result = 0;
42  for ($i = 0; $i < $kLen; $i++) {
43  $result |= (ord($knownString[$i]) ^ ord($userString[$i]));
44  }
45 
46  // They are only identical strings if $result is exactly 0...
47  return 0 === $result;
48  }
49 }
php