Compare commits
2 Commits
08394be35e
...
645e98cd6a
Author | SHA1 | Date |
---|---|---|
|
645e98cd6a | |
|
a31939cb87 |
|
@ -92,6 +92,11 @@ class RateLimiter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function attempt($username, $ipAddress) {
|
public function attempt($username, $ipAddress) {
|
||||||
|
// Skip rate limiting for whitelisted IPs
|
||||||
|
if ($this->isIpWhitelisted($ipAddress)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Clean old attempts
|
// Clean old attempts
|
||||||
$this->clearOldAttempts();
|
$this->clearOldAttempts();
|
||||||
|
|
||||||
|
@ -108,10 +113,10 @@ class RateLimiter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tooManyAttempts($username, $ipAddress) {
|
public function tooManyAttempts($username, $ipAddress) {
|
||||||
$sql = "SELECT COUNT(*) as attempts
|
$sql = "SELECT COUNT(*) as attempts
|
||||||
FROM {$this->tableName}
|
FROM {$this->tableName}
|
||||||
WHERE ip_address = :ip
|
WHERE ip_address = :ip
|
||||||
AND username = :username
|
AND username = :username
|
||||||
AND attempted_at > datetime('now', '-' || :minutes || ' minutes')";
|
AND attempted_at > datetime('now', '-' || :minutes || ' minutes')";
|
||||||
|
|
||||||
$stmt = $this->db->prepare($sql);
|
$stmt = $this->db->prepare($sql);
|
||||||
|
@ -126,7 +131,7 @@ class RateLimiter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clearOldAttempts() {
|
public function clearOldAttempts() {
|
||||||
$sql = "DELETE FROM {$this->tableName}
|
$sql = "DELETE FROM {$this->tableName}
|
||||||
WHERE attempted_at < datetime('now', '-' || :minutes || ' minutes')";
|
WHERE attempted_at < datetime('now', '-' || :minutes || ' minutes')";
|
||||||
|
|
||||||
$stmt = $this->db->prepare($sql);
|
$stmt = $this->db->prepare($sql);
|
||||||
|
@ -136,10 +141,10 @@ class RateLimiter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRemainingAttempts($username, $ipAddress) {
|
public function getRemainingAttempts($username, $ipAddress) {
|
||||||
$sql = "SELECT COUNT(*) as attempts
|
$sql = "SELECT COUNT(*) as attempts
|
||||||
FROM {$this->tableName}
|
FROM {$this->tableName}
|
||||||
WHERE ip_address = :ip
|
WHERE ip_address = :ip
|
||||||
AND username = :username
|
AND username = :username
|
||||||
AND attempted_at > datetime('now', '-' || :minutes || ' minutes')";
|
AND attempted_at > datetime('now', '-' || :minutes || ' minutes')";
|
||||||
|
|
||||||
$stmt = $this->db->prepare($sql);
|
$stmt = $this->db->prepare($sql);
|
||||||
|
|
Loading…
Reference in New Issue