From 00e992b175f72d5ed70adc5e00a40c64e1b73ae3 Mon Sep 17 00:00:00 2001 From: Stanislav Chzhen Date: Tue, 26 Aug 2025 15:31:31 +0300 Subject: [PATCH] home: imp code --- internal/home/authhttp.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/internal/home/authhttp.go b/internal/home/authhttp.go index 349e8483..ff054b24 100644 --- a/internal/home/authhttp.go +++ b/internal/home/authhttp.go @@ -506,21 +506,25 @@ func (mw *authMiddlewareDefault) userFromRequestBasicAuth( return nil, fmt.Errorf("login attempt blocked for %s", left) } + defer func() { + if err != nil { + rateLimiter.inc(remoteIP) + + return + } + + rateLimiter.remove(remoteIP) + }() + user, _ = mw.users.ByLogin(ctx, aghuser.Login(login)) if user == nil { - rateLimiter.inc(remoteIP) - return nil, errInvalidLogin } ok = user.Password.Authenticate(ctx, pass) if !ok { - rateLimiter.inc(remoteIP) - return nil, errInvalidLogin } - rateLimiter.remove(remoteIP) - return user, nil }