From dfac9ddca8f5ed31de836eb00b65ac0abcb0afad Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Wed, 25 Dec 2024 05:49:13 +0300 Subject: [PATCH] sec: add failed attempts for 2FA --- Security/Services/AuthService.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Security/Services/AuthService.cs b/Security/Services/AuthService.cs index 4951608..732c031 100644 --- a/Security/Services/AuthService.cs +++ b/Security/Services/AuthService.cs @@ -156,8 +156,13 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I var totp = new TotpService(firstTokenAuth.Secret); if (!totp.VerifyToken(code)) + { + await RecordFailedLoginAttempt(requestContext.Fingerprint, firstTokenAuth.UserId, cancellation); throw new SecurityException("Invalid verification code. Please try again."); } + + await ResetFailedLoginAttempts(requestContext.Fingerprint, cancellation); + } break; default: throw new InvalidOperationException("Unsupported authorization method.");