ValidateTOTP returns true if given passcode is valid for two-factor authentication token. It also returns possible validation error.
(passcode string)
| 25 | // ValidateTOTP returns true if given passcode is valid for two-factor authentication token. |
| 26 | // It also returns possible validation error. |
| 27 | func (t *TwoFactor) ValidateTOTP(passcode string) (bool, error) { |
| 28 | secret, err := base64.StdEncoding.DecodeString(t.Secret) |
| 29 | if err != nil { |
| 30 | return false, errors.Newf("DecodeString: %v", err) |
| 31 | } |
| 32 | decryptSecret, err := com.AESGCMDecrypt(cryptoutil.MD5Bytes(conf.Security.SecretKey), secret) |
| 33 | if err != nil { |
| 34 | return false, errors.Newf("AESGCMDecrypt: %v", err) |
| 35 | } |
| 36 | return totp.Validate(passcode, string(decryptSecret)), nil |
| 37 | } |
| 38 | |
| 39 | // DeleteTwoFactor removes two-factor authentication token and recovery codes of given user. |
| 40 | func DeleteTwoFactor(userID int64) (err error) { |
no test coverage detected