Skip to content

Commit 2d54204

Browse files
committed
fix expiry, add trusted IPs option
1 parent 1889635 commit 2d54204

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

init.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function initDatabase() {
4141
data TEXT
4242
)',
4343
'CREATE TABLE IF NOT EXISTS ipAttempts (
44-
ip VARCHAR(255) NOT NULL PRIMARY KEY,
44+
ip VARCHAR(255) NOT NULL,
4545
type VARCHAR(255) NOT NULL,
4646
expires NOT NULL
4747
)',

lib/IpAttempts.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ private static function connect() {
1010
}
1111

1212
public static function logFailedAttempt($ip, $type, $expires) {
13+
if (in_array($ip, TRUSTED_IPS)) {
14+
return;
15+
}
16+
1317
self::connect();
1418

1519
$query = self::$pdo->prepare(
@@ -18,11 +22,15 @@ public static function logFailedAttempt($ip, $type, $expires) {
1822
$query->execute([
1923
':ip' => $ip,
2024
':type' => $type,
21-
':expires' => $expires->getTimestamp()
25+
':expires' => $expires
2226
]);
2327
}
2428

2529
public static function getAttemptsCount($ip, $type) {
30+
if (in_array($ip, TRUSTED_IPS)) {
31+
return 0;
32+
}
33+
2634
self::connect();
2735

2836
$now = new \DateTime();

0 commit comments

Comments
 (0)