VerifyOTPHash compares a candidate plaintext OTP against a stored HMAC digest in constant time.
(candidate, stored, key string)
| 21 | // VerifyOTPHash compares a candidate plaintext OTP against a stored HMAC |
| 22 | // digest in constant time. |
| 23 | func VerifyOTPHash(candidate, stored, key string) bool { |
| 24 | expected := HashOTP(candidate, key) |
| 25 | return subtle.ConstantTimeCompare([]byte(expected), []byte(stored)) == 1 |
| 26 | } |