Documentation / @zerotal/core / index / safeEqual
Function: safeEqual()
safeEqual(
a,b):boolean
Defined in: support/crypto.ts:23
Constant-time string comparison.
Returns false (rather than throwing) when lengths differ. Length is not
secret for the token formats used across the framework (fixed-length
hashes, hex digests, OTP codes), so the early return does not leak
anything useful.
Parameters
a
string
b
string
Returns
boolean
Example
if (!safeEqual(candidateHash, storedHash)) throw new InvalidTokenError();