From 8b75583a0470035d93320fc14c8d8e7f69e4a61a Mon Sep 17 00:00:00 2001
From: Robert Willert <rwillert@users.noreply.github.com>
Date: Tue, 17 Dec 2024 17:54:18 +0100
Subject: [PATCH] add login logging for banning brute force attacks

---
 handler/routes.go | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/handler/routes.go b/handler/routes.go
index ede3654..7e94173 100644
--- a/handler/routes.go
+++ b/handler/routes.go
@@ -75,7 +75,7 @@ func Login(db store.IStore) echo.HandlerFunc {
 
 		dbuser, err := db.GetUserByName(username)
 		if err != nil {
-			log.Infof("Cannot query user %s from DB", username)
+			log.Warnf("Invalid credentials. Cannot query user %s from DB (%s)", username, c.Request().RemoteAddr)
 			return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{false, "Invalid credentials"})
 		}
 
@@ -130,9 +130,11 @@ func Login(db store.IStore) echo.HandlerFunc {
 			cookie.SameSite = http.SameSiteLaxMode
 			c.SetCookie(cookie)
 
+			log.Infof("Logged in successfully user %s (%s)", username, c.Request().RemoteAddr)
 			return c.JSON(http.StatusOK, jsonHTTPResponse{true, "Logged in successfully"})
 		}
 
+		log.Warnf("Invalid credentials user %s (%s)", username, c.Request().RemoteAddr)
 		return c.JSON(http.StatusUnauthorized, jsonHTTPResponse{false, "Invalid credentials"})
 	}
 }