_setDefaults(); if (empty($user)) { $this->Bruteforce = ClassRegistry::init('Bruteforce'); // do the anti-bruteforce checks $usernameField = $this->authenticate['Form']['fields']['username']; if (isset($this->request->data['User'][$usernameField])) { $username = $this->request->data['User'][$usernameField]; if (!$this->Bruteforce->isBlacklisted($_SERVER['REMOTE_ADDR'], $username)) { // user - ip combination is not blacklisted // check if the user credentials are valid $user = $this->identify($this->request, $this->response); unset($user['gpgkey']); if ($user === false) { $this->Log = ClassRegistry::init('Log'); $this->Log->create(); $log = array( 'org' => 'SYSTEM', 'model' => 'User', 'model_id' => 0, 'email' => $username, 'action' => 'login_fail', 'title' => 'Failed login attempt', 'change' => null, ); $this->Log->save($log); // insert row in Bruteforce table $this->Bruteforce->insert($_SERVER['REMOTE_ADDR'], $username); // do nothing as user is not logged in } } else { // user - ip combination has reached the amount of maximum attempts in the timeframe throw new ForbiddenException('You have reached the maximum number of login attempts. Please wait ' . Configure::read('SecureAuth.expire') . ' seconds and try again.'); } } else { // user didn't fill in all the form fields, nothing to do } } if ($user) { $this->Session->renew(); $this->Session->write(self::$sessionKey, $user); } return $this->loggedIn(); } }