LoginAttempts::MaxLoginAttemptsExceeded PHP Method

MaxLoginAttemptsExceeded() public static method

Checks if failed login attempts exceeds the number of failed login attempts saved in the System Preferences.
public static MaxLoginAttemptsExceeded ( ) : boolean
return boolean
    public static function MaxLoginAttemptsExceeded()
    {
        global $g_ado_db;
        $userIp = getenv('REMOTE_ADDR');
        $preferencesService = \Zend_Registry::get('container')->getService('system_preferences_service');
        $maxFailuresAllowed = $preferencesService->LoginFailedAttemptsNum;
        if (is_null($maxFailuresAllowed)) {
            $maxFailuresAllowed = 3;
        }
        $queryStr = "SELECT COUNT(*) FROM FailedLoginAttempts WHERE ip_address='" . $userIp . "'";
        $ip_num = $g_ado_db->GetOne($queryStr);
        if ($ip_num >= $maxFailuresAllowed) {
            return true;
        } else {
            return false;
        }
    }

Usage Example

 /**
  *
  * TODO: Add Recaptcha, but first:
  * * add recaptcha config to newscoop preferences not in recaptcha plugin config
  * * remove old recaptcha libraries
  * * reenable failed logins counter here Newscoop\NewscoopBundle\Security\Http\Authentication\AuthenticationFailedHandler
  * * clean code
  * 
  * {@inheritdoc}
  */
 protected function attemptAuthentication(Request $request)
 {
     if ($request->request->has('captcha_code', $request->query->has('captcha_code')) && \LoginAttempts::MaxLoginAttemptsExceeded()) {
         if (false) {
             throw new AuthenticationException($translator->trans("CAPTCHA code is not valid.  Please try again.", array(), 'home'));
         }
     }
     return parent::attemptAuthentication($request);
 }
All Usage Examples Of LoginAttempts::MaxLoginAttemptsExceeded