/**
  * @param null|\User $user
  * @param AuthenticationResponse $response
  */
 public function postAuthentication($user, AuthenticationResponse $response)
 {
     if ($response->status !== AuthenticationResponse::PASS) {
         return;
     } elseif (!$this->passwordAttemptThrottle) {
         return;
     }
     $data = $this->manager->getAuthenticationSessionData('LoginThrottle');
     if (!$data) {
         $this->logger->error('throttler data not found for {user}', ['user' => $user->getName()]);
         return;
     }
     foreach ($data['users'] as $name) {
         $this->passwordAttemptThrottle->clear($name, $data['ip']);
     }
 }
 /**
  * @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
  */
 public static function clearLoginThrottle($username)
 {
     wfDeprecated(__METHOD__, "1.27");
     global $wgRequest;
     $username = User::getCanonicalName($username, 'usable') ?: $username;
     $throttler = new Throttler();
     return $throttler->clear($username, $wgRequest->getIP());
 }
Exemplo n.º 3
0
 public function testClear()
 {
     $cache = new \HashBagOStuff();
     $throttler = new Throttler([['count' => 1, 'seconds' => 10]], ['cache' => $cache]);
     $throttler->setLogger(new NullLogger());
     $result = $throttler->increase('SomeUser', '1.2.3.4');
     $this->assertFalse($result, 'should not throttle');
     $result = $throttler->increase('SomeUser', '1.2.3.4');
     $this->assertSame(['throttleIndex' => 0, 'count' => 1, 'wait' => 10], $result);
     $result = $throttler->increase('OtherUser', '1.2.3.4');
     $this->assertFalse($result, 'should not throttle');
     $result = $throttler->increase('OtherUser', '1.2.3.4');
     $this->assertSame(['throttleIndex' => 0, 'count' => 1, 'wait' => 10], $result);
     $throttler->clear('SomeUser', '1.2.3.4');
     $result = $throttler->increase('SomeUser', '1.2.3.4');
     $this->assertFalse($result, 'should not throttle');
     $result = $throttler->increase('OtherUser', '1.2.3.4');
     $this->assertSame(['throttleIndex' => 0, 'count' => 1, 'wait' => 10], $result);
 }