about summary refs log tree commit diff stats
path: root/classes
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-06-21 14:49:08 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-06-21 14:49:08 +0300
commit17296a2ef8fa2658dca471285bce40ee67469179 (patch)
tree6a6acc9a378e2402d048a02e47b5ab99dc5247e2 /classes
parent064a21f5b8f365629cc8cfd1fae7220a959750f1 (diff)
downloadthe-epube-17296a2ef8fa2658dca471285bce40ee67469179.tar.gz
the-epube-17296a2ef8fa2658dca471285bce40ee67469179.tar.xz
we don't need to update this twice in case of valid login
Diffstat (limited to 'classes')
-rw-r--r--classes/Handler/LoginHandler.php16
1 files changed, 12 insertions, 4 deletions
diff --git a/classes/Handler/LoginHandler.php b/classes/Handler/LoginHandler.php
index ab3a099..7b6fabb 100644
--- a/classes/Handler/LoginHandler.php
+++ b/classes/Handler/LoginHandler.php
@@ -37,13 +37,20 @@ class LoginHandler implements RequestHandlerInterface
             }
         }
 
-        // Record this attempt timestamp before expensive password verification.
-        $user->last_auth_attempt = time();
-        $user->save();
-
         return false;
     }
 
+    /**
+     * Record a failed authentication attempt for rate limiting purposes.
+     */
+    private function recordFailedAttempt(object $user): void
+    {
+        if (Config::get_schema_version() >= 3) {
+            $user->last_auth_attempt = time();
+            $user->save();
+        }
+    }
+
     /** @return array{array{result: string, user: string, csrf_token: string}|null, int} */
     private function doLocalLogin(string $username, string $password): array
     {
@@ -68,6 +75,7 @@ class LoginHandler implements RequestHandlerInterface
             : password_verify($password, $user->pass);
 
         if (!$valid) {
+            $this->recordFailedAttempt($user);
             return [null, self::USER_WRONG_PASSWORD];
         }