MCPcopy Create free account
hub / github.com/gogs/gogs / ValidateTOTP

Method ValidateTOTP

internal/database/two_factor.go:27–37  ·  view source on GitHub ↗

ValidateTOTP returns true if given passcode is valid for two-factor authentication token. It also returns possible validation error.

(passcode string)

Source from the content-addressed store, hash-verified

25// ValidateTOTP returns true if given passcode is valid for two-factor authentication token.
26// It also returns possible validation error.
27func (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.
40func DeleteTwoFactor(userID int64) (err error) {

Callers 1

LoginTwoFactorPostFunction · 0.80

Calls 3

MD5BytesFunction · 0.92
stringFunction · 0.85
ValidateMethod · 0.45

Tested by

no test coverage detected