/** * Get the authentication failed error messages * @return array Data */ private function _getAuthenticationFailedErrorMessage() { $clang = $this->getController()->lang; $aData = array(); $userHostAddress = Yii::app()->request->getUserHostAddress(); $bUserNotFound = Failed_login_attempts::model()->addAttempt($userHostAddress); if ($bUserNotFound) { $aData['errormsg'] = $clang->gT('Incorrect username and/or password!'); $aData['maxattempts'] = ''; } $bLockedOut = Failed_login_attempts::model()->isLockedOut($userHostAddress); if ($bLockedOut) { $aData['maxattempts'] = sprintf($clang->gT('You have exceeded the number of maximum login attempts. Please wait %d minutes before trying again.'), Yii::app()->getConfig('timeOutTime') / 60); } return $aData; }
/** * Tries to login with username and password * * @access protected * @param string $sUsername The username * @param mixed $sPassword The Password * @return bool */ protected function _doLogin($sUsername, $sPassword) { if (Failed_login_attempts::model()->isLockedOut()) { return false; } $identity = new UserIdentity(sanitize_user($sUsername), $sPassword); if (!$identity->authenticate()) { Failed_login_attempts::model()->addAttempt(); return false; } else { return true; } }
/** * Creates an attempt * * @access public * @return true */ public function addAttempt() { $timestamp = date("Y-m-d H:i:s"); $ip = substr(Yii::app()->request->getUserHostAddress(), 0, 40); $row = $this->findByAttributes(array('ip' => $ip)); if ($row !== null) { $row->number_attempts = $row->number_attempts + 1; $row->last_attempt = $timestamp; $row->save(); } else { $record = new Failed_login_attempts(); $record->ip = $ip; $record->number_attempts = 1; $record->last_attempt = $timestamp; $record->save(); } return true; }