MCPcopy Create free account
hub / github.com/authorizerdev/authorizer / HashOTP

Function HashOTP

internal/crypto/otp.go:15–19  ·  view source on GitHub ↗

HashOTP returns the hex-encoded HMAC-SHA256 of the OTP value under the supplied server key. OTPs are short-lived (minutes) so we do not need a reversible primitive — only the verifier needs to be able to recompute the digest from a candidate value. This means an offline DB dump no longer reveals usa

(otp, key string)

Source from the content-addressed store, hash-verified

13// the digest from a candidate value. This means an offline DB dump no
14// longer reveals usable OTPs.
15func HashOTP(otp, key string) string {
16 h := hmac.New(sha256.New, []byte(key))
17 h.Write([]byte(otp))
18 return hex.EncodeToString(h.Sum(nil))
19}
20
21// VerifyOTPHash compares a candidate plaintext OTP against a stored HMAC
22// digest in constant time.

Callers 13

TestResendOTPFunction · 0.92
TestResetPasswordFunction · 0.92
TestVerifyOTPFunction · 0.92
ResendOTPMethod · 0.92
LoginMethod · 0.92
SignUpMethod · 0.92
ForgotPasswordMethod · 0.92
VerifyOTPHashFunction · 0.85
TestHashOTP_RoundTripFunction · 0.85

Calls

no outgoing calls

Tested by 8

TestResendOTPFunction · 0.74
TestResetPasswordFunction · 0.74
TestVerifyOTPFunction · 0.74
TestHashOTP_RoundTripFunction · 0.68