58 $this->throttleSettings = array_intersect_key( $params,
59 [
'accountCreationThrottle' =>
true,
'passwordAttemptThrottle' =>
true ] );
60 $this->cache = $params[
'cache'] ?? \ObjectCache::getLocalClusterInstance();
74 $this->throttleSettings += [
77 'passwordAttemptThrottle' => $this->config->get(
'PasswordAttemptThrottle' ),
80 if ( !empty( $this->throttleSettings[
'accountCreationThrottle'] ) ) {
81 $this->accountCreationThrottle =
new Throttler(
82 $this->throttleSettings[
'accountCreationThrottle'], [
83 'type' =>
'acctcreate',
84 'cache' => $this->cache,
88 if ( !empty( $this->throttleSettings[
'passwordAttemptThrottle'] ) ) {
89 $this->passwordAttemptThrottle =
new Throttler(
90 $this->throttleSettings[
'passwordAttemptThrottle'], [
92 'cache' => $this->cache,
99 if ( !$this->accountCreationThrottle || !$creator->isPingLimitable() ) {
100 return \StatusValue::newGood();
103 $ip = $this->manager->getRequest()->getIP();
105 if ( !$this->
getHookRunner()->onExemptFromAccountCreationThrottle( $ip ) ) {
106 $this->logger->debug( __METHOD__ .
": a hook allowed account creation w/o throttle" );
107 return \StatusValue::newGood();
110 $result = $this->accountCreationThrottle->increase(
null, $ip, __METHOD__ );
112 $message =
wfMessage(
'acct_creation_throttle_hit' )->params( $result[
'count'] )
113 ->durationParams( $result[
'wait'] );
114 return \StatusValue::newFatal( $message );
117 return \StatusValue::newGood();
121 if ( !$this->passwordAttemptThrottle ) {
122 return \StatusValue::newGood();
125 $ip = $this->manager->getRequest()->getIP();
128 }
catch ( \UnexpectedValueException $e ) {
134 if ( $username !==
null ) {
135 $usernames = $this->manager->normalizeUsername( $username );
137 $usernames = [ null ];
140 foreach ( $usernames as $name ) {
141 $r = $this->passwordAttemptThrottle->increase( $name, $ip, __METHOD__ );
142 if ( $r && ( !$result || $result[
'wait'] < $r[
'wait'] ) ) {
148 $message =
wfMessage(
'login-throttled' )->durationParams( $result[
'wait'] );
149 return \StatusValue::newFatal( $message );
151 $this->manager->setAuthenticationSessionData(
'LoginThrottle',
152 [
'users' => $usernames,
'ip' => $ip ] );
153 return \StatusValue::newGood();
164 } elseif ( !$this->passwordAttemptThrottle ) {
168 $data = $this->manager->getAuthenticationSessionData(
'LoginThrottle' );
172 $this->logger->info(
'throttler data not found for {user}', [
'user' => $user->getName() ] );
176 foreach ( $data[
'users'] as $name ) {
177 $this->passwordAttemptThrottle->clear( $name, $data[
'ip'] );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Class representing a cache/ephemeral data store.