ElggCrypto::areEqual PHP Method

areEqual() public method

Are two strings equal (compared in constant time)?
Author: Anthony Ferrara ([email protected])
public areEqual ( string $str1, string $str2 ) : boolean
$str1 string First string to compare
$str2 string Second string to compare
return boolean Based on password_verify in PasswordCompat
    public function areEqual($str1, $str2)
    {
        $len1 = $this->strlen($str1);
        $len2 = $this->strlen($str2);
        if ($len1 !== $len2) {
            return false;
        }
        $status = 0;
        for ($i = 0; $i < $len1; $i++) {
            $status |= ord($str1[$i]) ^ ord($str2[$i]);
        }
        return $status === 0;
    }