-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy paththrottle.php
49 lines (39 loc) · 801 Bytes
/
throttle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
class Throttle
{
public static $prefix = 'signin_throttle_for_';
public static function increase($key)
{
$key = static::$prefix.$key;
$failed = 1;
if(Cache::has($key))
{
$tmp = Cache::get($key);
$failed += $tmp[0];
}
Cache::put($key, array($failed, time()), 10);
}
public static function remove($key)
{
$key = static::$prefix.$key;
if(Cache::has($key))
{
Cache::forget($key);
}
}
public static function is_over($key)
{
$key = static::$prefix.$key;
if(Cache::has($key))
{
$tmp = Cache::get($key);
// if the time (in seconds) between attempts to access one account is less than the ^2 of failed attempts block the access
if((time() - $tmp[1]) < ($tmp[0]*$tmp[0]))
{
return true;
}
}
return false;
}
}
?>