LoginAttempts::DeleteOldLoginAttempts PHP Method

DeleteOldLoginAttempts() public static method

Delete IP records older than 12 hours from the database.
public static DeleteOldLoginAttempts ( ) : void
return void
    public static function DeleteOldLoginAttempts()
    {
        global $g_ado_db;
        $now = time();
        // Records are kept for 12 hours.
        $diff = $now - 43200;
        $queryStr = "DELETE FROM FailedLoginAttempts WHERE time_of_attempt <=" . $diff;
        $g_ado_db->Execute($queryStr);
    }

Usage Example

 /**
  * This is called when an interactive authentication attempt succeeds. This
  * is called by authentication listeners inheriting from AbstractAuthenticationListener.
  * @param  Request        $request
  * @param  TokenInterface $token
  * @return Response       The response to return
  */
 public function onAuthenticationSuccess(Request $request, TokenInterface $token)
 {
     $user = $token->getUser();
     // This should actually be handle by the AuthenticationFailedHandler
     if (!$user->isAdmin()) {
         // can't go into admin
         $request->getSession()->set(SecurityContextInterface::AUTHENTICATION_ERROR, new AuthenticationException('User is not an admin.'));
         return $this->httpUtils->createRedirectResponse($request, 'admin_login');
     }
     \LoginAttempts::DeleteOldLoginAttempts();
     \LoginAttempts::ClearLoginAttemptsForIp();
     $zendAuth = \Zend_Auth::getInstance();
     $this->authAdapter->setUsername($user->getUsername())->setPassword($request->request->get('_password'))->setAdmin(true);
     $zendAuth->authenticate($this->authAdapter);
     $OAuthtoken = $this->userService->loginUser($user, 'oauth_authorize');
     $session = $request->getSession();
     $session->set('_security_oauth_authorize', serialize($OAuthtoken));
     $frontendToken = $this->userService->loginUser($user, 'frontend_area');
     $session = $request->getSession();
     $session->set('_security_frontend_area', serialize($frontendToken));
     \Article::UnlockByUser($user->getId());
     $request->setLocale($request->request->get('login_language'));
     $this->setNoCacheCookie($request);
     $user->setLastLogin(new \DateTime());
     $this->em->flush();
     if ($request->get('ajax') === 'true') {
         // close popup with login.
         return new Response("<script type=\"text/javascript\">window.parent.g_security_token = '" . \SecurityToken::GetToken() . "';window.parent.\$(window.parent.document.body).data('loginDialog').dialog('close');window.parent.setSecurityToken(window.parent.g_security_token);</script>");
     }
     return parent::onAuthenticationSuccess($request, $token);
 }
All Usage Examples Of LoginAttempts::DeleteOldLoginAttempts