summaryrefslogtreecommitdiff
path: root/lib/VNDB/DB
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2014-08-29 10:54:36 +0200
committerYorhel <git@yorhel.nl>2014-08-29 10:54:36 +0200
commit9a1bd46a568094ff62cfc85bc488b116042718b8 (patch)
treee580afad4f318a1c5f4c98047beaa6796b3f14e3 /lib/VNDB/DB
parentc27d4e6b509a655d81e36469bb881afc287596e8 (diff)
Throttle failed login attempts (10/day)
Diffstat (limited to 'lib/VNDB/DB')
-rw-r--r--lib/VNDB/DB/Users.pm16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/VNDB/DB/Users.pm b/lib/VNDB/DB/Users.pm
index 0ca56780..a96b1f99 100644
--- a/lib/VNDB/DB/Users.pm
+++ b/lib/VNDB/DB/Users.pm
@@ -9,6 +9,7 @@ our @EXPORT = qw|
dbUserGet dbUserEdit dbUserAdd dbUserDel dbUserPrefSet
dbSessionAdd dbSessionDel dbSessionUpdateLastUsed
dbNotifyGet dbNotifyMarkRead dbNotifyRemove
+ dbThrottleGet dbThrottleSet
|;
@@ -230,5 +231,20 @@ sub dbNotifyRemove {
}
+# ip
+sub dbThrottleGet {
+ my $s = shift;
+ my $t = $s->dbRow('SELECT timeout FROM login_throttle WHERE ip = ?', shift)->{timeout};
+ return $t && $t >= time ? $t : time;
+}
+
+# ip, timeout
+sub dbThrottleSet {
+ my($s, $ip, $timeout) = @_;
+ !$timeout ? $s->dbExec('DELETE FROM login_throttle WHERE ip = ?', $ip)
+ : $s->dbExec('UPDATE login_throttle SET timeout = ? WHERE ip = ?', $timeout, $ip)
+ || $s->dbExec('INSERT INTO login_throttle (ip, timeout) VALUES (?, ?)', $ip, $timeout);
+}
+
1;