|
@@ 96-106 (lines=11) @@
|
| 93 |
|
* @param string $uid
|
| 94 |
|
* @return int
|
| 95 |
|
*/
|
| 96 |
|
public function getSuspiciousActivityCountForUid($uid) {
|
| 97 |
|
$builder = $this->connection->getQueryBuilder();
|
| 98 |
|
$thresholdTime = (new \DateTime())->modify("-". $this->config->getBruteForceProtectionTimeThreshold() . "second")->getTimestamp();
|
| 99 |
|
$attempts = $builder->selectAlias($builder->createFunction('COUNT(*)'), 'count')
|
| 100 |
|
->from('failed_login_attempts')
|
| 101 |
|
->where($builder->expr()->gt('attempted_at', $builder->createNamedParameter($thresholdTime)))
|
| 102 |
|
->andWhere($builder->expr()->eq('uid', $builder->createNamedParameter($uid)))
|
| 103 |
|
->execute()
|
| 104 |
|
->fetch();
|
| 105 |
|
return intval($attempts['count']);
|
| 106 |
|
}
|
| 107 |
|
|
| 108 |
|
/**
|
| 109 |
|
* @param string $ip
|
|
@@ 112-123 (lines=12) @@
|
| 109 |
|
* @param string $ip
|
| 110 |
|
* @return int
|
| 111 |
|
*/
|
| 112 |
|
public function getSuspiciousActivityCountForIp($ip) {
|
| 113 |
|
$builder = $this->connection->getQueryBuilder();
|
| 114 |
|
$thresholdTime = (new \DateTime())->modify("-". $this->config->getBruteForceProtectionTimeThreshold() . "second")->getTimestamp();
|
| 115 |
|
$attempts = $builder->selectAlias($builder->createFunction('COUNT(*)'), 'count')
|
| 116 |
|
->from('failed_login_attempts')
|
| 117 |
|
->where($builder->expr()->gt('attempted_at', $builder->createNamedParameter($thresholdTime)))
|
| 118 |
|
->andWhere($builder->expr()->eq('ip', $builder->createNamedParameter($ip)))
|
| 119 |
|
->execute()
|
| 120 |
|
->fetch();
|
| 121 |
|
return intval($attempts['count']);
|
| 122 |
|
}
|
| 123 |
|
|
| 124 |
|
/**
|
| 125 |
|
* @param string $ip
|
| 126 |
|
* @return int
|
|
@@ 128-140 (lines=13) @@
|
| 125 |
|
* @param string $ip
|
| 126 |
|
* @return int
|
| 127 |
|
*/
|
| 128 |
|
public function getLastFailedLoginAttemptTimeForIp($ip) {
|
| 129 |
|
$builder = $this->connection->getQueryBuilder();
|
| 130 |
|
$thresholdTime = (new \DateTime())->modify("-". $this->config->getBruteForceProtectionTimeThreshold() . "second")->getTimestamp();
|
| 131 |
|
$lastAttempt = $builder->select('attempted_at')
|
| 132 |
|
->from('failed_login_attempts')
|
| 133 |
|
->where($builder->expr()->gt('attempted_at', $builder->createNamedParameter($thresholdTime)))
|
| 134 |
|
->andWhere($builder->expr()->eq('ip', $builder->createNamedParameter($ip)))
|
| 135 |
|
->orderBy('attempted_at','DESC')
|
| 136 |
|
->setMaxResults(1)
|
| 137 |
|
->execute()
|
| 138 |
|
->fetch();
|
| 139 |
|
return intval($lastAttempt['attempted_at']);
|
| 140 |
|
}
|
| 141 |
|
|
| 142 |
|
/**
|
| 143 |
|
* @param string $ip
|