← All built-ins / hash_equals()
hash_equals()
hash_equals(string $haystack, string $needle): bool
Parameters
| Name | Type | Description |
|---|---|---|
| $known | string | expected value |
| $user | string | user-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)