Skip to content

Instantly share code, notes, and snippets.

@cheald
Created April 8, 2014 23:29
Show Gist options
  • Save cheald/10208531 to your computer and use it in GitHub Desktop.
Save cheald/10208531 to your computer and use it in GitHub Desktop.
function secure_compare($a, $b) {
if(strlen($a) == strlen($b)) {
$result = 0;
for($i = 0; $i < strlen($a); $i++) {
$result = $result | (ord($a[$i]) ^ ord($b[$i]));
}
return $result === 0;
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment