← All built-ins / hash_equals()

hash_equals()

hash_equals(string $haystack, string $needle): bool

Parameters

NameTypeDescription
$knownstringexpected value
$userstringuser-supplied value

Return value

true when equal — compared in constant time so timing attacks fail. Always use for secrets.

Example

var_dump(hash_equals("sig123", "sig123"));
var_dump(hash_equals("sig123", "sig124"));
bool(true)
bool(false)

See also

hash_hmac()password_verify()