class.bruteForceMapper.php
Gesponsorde koppelingen
PHP script bestanden
Code (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
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
<?php
/**
*
* @date 15 Aug 2012,
* @package Login System
*
*/
Class BruteForceMapper extends DataMapper {
/**
* @param object $bruteforce,
* @return mixed -> bool when failing, otherwishe array
*/
public function getByUsername(BruteForce $bruteforce, $fields = '*') {
$this->pdo->query("SELECT ".$fields." FROM brute_force WHERE insert_datetime >= NOW() - INTERVAL :attempts_time MINUTE AND username = :username GROUP BY username, ip HAVING (COUNT(username) >= :max_attempts)", array(':username' => $bruteforce->getUsername(), ':attempts_time' => $bruteforce->getTimeout(), ':max_attempts' => $bruteforce->getMaxAttempts()));
return $this->pdo->fetchAll();
}
/**
* @param object $bruteforce,
* @return mixed
*/
public function getByIp(Bruteforce $bruteforce, $fields = '*') {
$this->pdo->query("SELECT ".$fields." FROM brute_force WHERE insert_datetime >= NOW() - INTERVAL :attempts_time MINUTE AND ip = :ip GROUP BY username, ip HAVING (COUNT(username) >= :max_attempts)", array(':ip' => $bruteforce->getIp(), ':attempts_time' => $bruteforce->getTimeout(), ':max_attempts' => $bruteforce->getMaxAttempts()));
return $this->pdo->fetchAll();
}
/**
* @param object $bruteforce,
* @return bool true/false
*/
public function insert(BruteForce $bruteforce) {
return $this->pdo->query("INSERT INTO brute_force SET username = :username, ip = :ip, insert_datetime = NOW()", array(':username' => $bruteforce->getUsername(), ':ip' => $bruteforce->getIp()));
}
/**
* @param object $bruteforce,
* @return bool true/false
*/
public function deleteByTime(BruteForce $bruteforce) {
return $this->pdo->query("DELETE FROM brute_force WHERE insert_datetime < :insert_datetime", array(':insert_datetime' => date('Y-m-d H:i:s', time() - $bruteforce->getTimeout() * 60)));
}
}
?>
/**
*
* @date 15 Aug 2012,
* @package Login System
*
*/
Class BruteForceMapper extends DataMapper {
/**
* @param object $bruteforce,
* @return mixed -> bool when failing, otherwishe array
*/
public function getByUsername(BruteForce $bruteforce, $fields = '*') {
$this->pdo->query("SELECT ".$fields." FROM brute_force WHERE insert_datetime >= NOW() - INTERVAL :attempts_time MINUTE AND username = :username GROUP BY username, ip HAVING (COUNT(username) >= :max_attempts)", array(':username' => $bruteforce->getUsername(), ':attempts_time' => $bruteforce->getTimeout(), ':max_attempts' => $bruteforce->getMaxAttempts()));
return $this->pdo->fetchAll();
}
/**
* @param object $bruteforce,
* @return mixed
*/
public function getByIp(Bruteforce $bruteforce, $fields = '*') {
$this->pdo->query("SELECT ".$fields." FROM brute_force WHERE insert_datetime >= NOW() - INTERVAL :attempts_time MINUTE AND ip = :ip GROUP BY username, ip HAVING (COUNT(username) >= :max_attempts)", array(':ip' => $bruteforce->getIp(), ':attempts_time' => $bruteforce->getTimeout(), ':max_attempts' => $bruteforce->getMaxAttempts()));
return $this->pdo->fetchAll();
}
/**
* @param object $bruteforce,
* @return bool true/false
*/
public function insert(BruteForce $bruteforce) {
return $this->pdo->query("INSERT INTO brute_force SET username = :username, ip = :ip, insert_datetime = NOW()", array(':username' => $bruteforce->getUsername(), ':ip' => $bruteforce->getIp()));
}
/**
* @param object $bruteforce,
* @return bool true/false
*/
public function deleteByTime(BruteForce $bruteforce) {
return $this->pdo->query("DELETE FROM brute_force WHERE insert_datetime < :insert_datetime", array(':insert_datetime' => date('Y-m-d H:i:s', time() - $bruteforce->getTimeout() * 60)));
}
}
?>