checkMFALockout checks if the user has exceeded the MFA failure rate limit. Returns an error if the user is locked out due to too many failed MFA attempts.
(ctx context.Context, email string)
| 836 | // checkMFALockout checks if the user has exceeded the MFA failure rate limit. |
| 837 | // Returns an error if the user is locked out due to too many failed MFA attempts. |
| 838 | func (s *AuthService) checkMFALockout(ctx context.Context, email string) error { |
| 839 | count, err := s.countRecentLoginFailures(ctx, email, mfaLockoutWindow, errMsgInvalidMFACode, errMsgInvalidRecoveryCode) |
| 840 | if err != nil { |
| 841 | return connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to count recent MFA failures")) |
| 842 | } |
| 843 | |
| 844 | if count >= mfaMaxFailedAttempts { |
| 845 | return connect.NewError(connect.CodeResourceExhausted, errors.Errorf(errMsgTooManyMFA)) |
| 846 | } |
| 847 | |
| 848 | return nil |
| 849 | } |
| 850 | |
| 851 | func challengeMFACode(user *store.UserMessage, mfaCode string) error { |
| 852 | if !validateWithCodeAndSecret(mfaCode, user.MFAConfig.OtpSecret) { |
no test coverage detected