/** * Checks to see if the current user has exceeded the site * login attempt limit for a given time period * * @return bool */ public function hasExceededLoginLimit() { $params = \Component::params('com_users'); $limit = (int) $params->get('login_attempts_limit', 10); $timeframe = (int) $params->get('login_attempts_timeframe', 1); $result = true; // Get the user's tokens $threshold = date("Y-m-d H:i:s", strtotime(\Date::toSql() . " {$timeframe} hours ago")); $auths = new \Hubzero\User\Log\Auth(); $auths->whereEquals('username', $this->username)->whereEquals('status', 'failure')->where('logged', '>=', $threshold); if ($auths->count() < $limit) { $result = false; } return $result; }
/** * Checks to see if the current user has exceeded the site * login attempt limit for a given time period * * @param $user \Hubzero\User\User * * @return bool */ private function hasExceededLoginLimit($user) { $params = \Component::params('com_members'); $limit = (int) $params->get('login_attempts_limit', 10); $timeframe = (int) $params->get('login_attempts_timeframe', 1); $result = true; // Get the user's tokens $threshold = date("Y-m-d H:i:s", strtotime(\Date::toSql() . " {$timeframe} hours ago")); $auths = new \Hubzero\User\Log\Auth(); $auths->whereEquals('username', $user->username)->whereEquals('status', 'failure')->where('logged', '>=', $threshold); if ($auths->count() < $limit - 1) { $result = false; } else { // Log attempt to the database Hubzero\User\User::oneOrFail($user->id)->logger()->auth()->save(['username' => $user->username, 'status' => 'blocked']); } return $result; }