Ratelimits only failed login attempts
parent
45181c11c5
commit
8d64bf7c6e
|
@ -427,7 +427,12 @@ class RateLimiter {
|
||||||
return $result['total_attempts'] < $this->autoBlacklistThreshold;
|
return $result['total_attempts'] < $this->autoBlacklistThreshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function attempt($username, $ipAddress) {
|
public function attempt($username, $ipAddress, $failed = true) {
|
||||||
|
// Only record failed attempts
|
||||||
|
if (!$failed) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Record this attempt
|
// Record this attempt
|
||||||
$sql = "INSERT INTO {$this->authRatelimitTable} (ip_address, username) VALUES (:ip, :username)";
|
$sql = "INSERT INTO {$this->authRatelimitTable} (ip_address, username) VALUES (:ip, :username)";
|
||||||
$stmt = $this->db->prepare($sql);
|
$stmt = $this->db->prepare($sql);
|
||||||
|
|
|
@ -201,8 +201,7 @@ try {
|
||||||
],
|
],
|
||||||
'password' => [
|
'password' => [
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'required' => true,
|
'required' => true
|
||||||
'min' => 8
|
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -226,8 +225,8 @@ try {
|
||||||
throw new Exception(Feedback::get('LOGIN', 'TOO_MANY_ATTEMPTS')['message']);
|
throw new Exception(Feedback::get('LOGIN', 'TOO_MANY_ATTEMPTS')['message']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record this attempt
|
// Record this attempt before trying to login
|
||||||
$rateLimiter->attempt($username, $user_IP);
|
$rateLimiter->attempt($username, $user_IP, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt login
|
// Attempt login
|
||||||
|
@ -262,6 +261,7 @@ try {
|
||||||
if (isset($username)) {
|
if (isset($username)) {
|
||||||
$userId = $userObject->getUserId($username)[0]['id'] ?? 0;
|
$userId = $userObject->getUserId($username)[0]['id'] ?? 0;
|
||||||
$logObject->insertLog($userId, "Login: Failed login attempt for user \"$username\". IP: $user_IP. Reason: {$e->getMessage()}", 'user');
|
$logObject->insertLog($userId, "Login: Failed login attempt for user \"$username\". IP: $user_IP. Reason: {$e->getMessage()}", 'user');
|
||||||
|
$rateLimiter->attempt($username, $user_IP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue