Advertisement
Guest User

Untitled

a guest
Jul 12th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1.     public function executeLog(sfWebRequest $request)
  2.     {
  3.         if ($this->getUser()->isAuthenticated())
  4.         {
  5.             $this->getUser()->logOut();
  6.         }
  7.         else
  8.         {
  9.             //code against brute force
  10.             $time = sfDbConfigHandler::get('log_wait');
  11.             $max = sfDbConfigHandler::get('log_max');
  12.             if (!isset($_SESSION['log_try']))
  13.             {
  14.                 $_SESSION['log_try'] = array('wait' => strtotime($time), 'count' => 0);
  15.             }
  16.             ++$_SESSION['log_try']['count']; //here, because the check is just lower
  17.             if (-1 != $max && $_SESSION['log_try']['count'] > $max)
  18.             {
  19.                 if ($_SESSION['log_try']['wait'] < time())
  20.                 { //reset
  21.                     $_SESSION['log_try'] = array('wait' => strtotime($time), 'count' => 1);
  22.                 }
  23.                 else
  24.                 {
  25.                     $this->wait = $_SESSION['log_try']['wait'];
  26.                     return sfView::ERROR;
  27.                 }
  28.             }
  29.  
  30.             $this->forward404Unless($username = $request->getParameter('username'));
  31.             $this->forward404Unless($password = $request->getParameter('password'));
  32.  
  33.             $this->account = Doctrine_Core::getTable('Account')
  34.                             ->findOneByUsernameAndPasswordAndBanned($username, $password, false);
  35.             if ($this->account)
  36.             {
  37.                 /**
  38.                 $this->forward404If($this->account->getValidationToken());
  39.                  */
  40.                 $this->getUser()->logIn($this->account);
  41.                 unset($_SESSION['log_try']); //reset attempts infos
  42.             }
  43.         }
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement