MCPcopy
hub / github.com/pquerna/otp / ValidateCustom

Function ValidateCustom

hotp/hotp.go:149–166  ·  view source on GitHub ↗

ValidateCustom validates an HOTP with customizable options. Most users should use Validate().

(passcode string, counter uint64, secret string, opts ValidateOpts)

Source from the content-addressed store, hash-verified

147// ValidateCustom validates an HOTP with customizable options. Most users should
148// use Validate().
149func ValidateCustom(passcode string, counter uint64, secret string, opts ValidateOpts) (bool, error) {
150 passcode = strings.TrimSpace(passcode)
151
152 if len(passcode) != opts.Digits.Length() {
153 return false, otp.ErrValidateInputInvalidLength
154 }
155
156 otpstr, err := GenerateCodeCustom(secret, counter, opts)
157 if err != nil {
158 return false, err
159 }
160
161 if subtle.ConstantTimeCompare([]byte(otpstr), []byte(passcode)) == 1 {
162 return true, nil
163 }
164
165 return false, nil
166}
167
168// GenerateOpts provides options for .Generate()
169type GenerateOpts struct {

Callers 6

ValidateCustomFunction · 0.92
ValidateFunction · 0.70
TestValidateRFCMatrixFunction · 0.70
TestValidateInvalidFunction · 0.70
TestValidatePaddingFunction · 0.70

Calls 2

LengthMethod · 0.80
GenerateCodeCustomFunction · 0.70

Tested by 4

TestValidateRFCMatrixFunction · 0.56
TestValidateInvalidFunction · 0.56
TestValidatePaddingFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…