ValidateCustom validates an HOTP with customizable options. Most users should use Validate().
(passcode string, counter uint64, secret string, opts ValidateOpts)
| 147 | // ValidateCustom validates an HOTP with customizable options. Most users should |
| 148 | // use Validate(). |
| 149 | func 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() |
| 169 | type GenerateOpts struct { |
searching dependent graphs…