59 $this->throttleSettings = array_intersect_key( $params,
60 [
'accountCreationThrottle' =>
true,
'passwordAttemptThrottle' =>
true ] );
61 $this->cache = $params[
'cache'] ?? \ObjectCache::getLocalClusterInstance();
75 $this->throttleSettings += [
78 'passwordAttemptThrottle' =>
82 if ( !empty( $this->throttleSettings[
'accountCreationThrottle'] ) ) {
83 $this->accountCreationThrottle =
new Throttler(
84 $this->throttleSettings[
'accountCreationThrottle'], [
85 'type' =>
'acctcreate',
86 'cache' => $this->cache,
90 if ( !empty( $this->throttleSettings[
'passwordAttemptThrottle'] ) ) {
91 $this->passwordAttemptThrottle =
new Throttler(
92 $this->throttleSettings[
'passwordAttemptThrottle'], [
94 'cache' => $this->cache,
101 if ( !$this->accountCreationThrottle || !$creator->isPingLimitable() ) {
102 return \StatusValue::newGood();
105 $ip = $this->manager->getRequest()->getIP();
107 if ( !$this->
getHookRunner()->onExemptFromAccountCreationThrottle( $ip ) ) {
108 $this->logger->debug( __METHOD__ .
": a hook allowed account creation w/o throttle" );
109 return \StatusValue::newGood();
112 $result = $this->accountCreationThrottle->increase(
null, $ip, __METHOD__ );
114 $message =
wfMessage(
'acct_creation_throttle_hit' )->params( $result[
'count'] )
115 ->durationParams( $result[
'wait'] );
116 return \StatusValue::newFatal( $message );
119 return \StatusValue::newGood();
123 if ( !$this->passwordAttemptThrottle ) {
124 return \StatusValue::newGood();
127 $ip = $this->manager->getRequest()->getIP();
130 }
catch ( \UnexpectedValueException $e ) {
136 if ( $username !==
null ) {
137 $usernames = $this->manager->normalizeUsername( $username );
139 $usernames = [ null ];
142 foreach ( $usernames as $name ) {
143 $r = $this->passwordAttemptThrottle->increase( $name, $ip, __METHOD__ );
144 if ( $r && ( !$result || $result[
'wait'] < $r[
'wait'] ) ) {
150 $message =
wfMessage(
'login-throttled' )->durationParams( $result[
'wait'] );
151 return \StatusValue::newFatal( $message );
153 $this->manager->setAuthenticationSessionData(
'LoginThrottle',
154 [
'users' => $usernames,
'ip' => $ip ] );
155 return \StatusValue::newGood();
166 } elseif ( !$this->passwordAttemptThrottle ) {
170 $data = $this->manager->getAuthenticationSessionData(
'LoginThrottle' );
174 $this->logger->info(
'throttler data not found for {user}', [
'user' => $user->getName() ] );
178 foreach ( $data[
'users'] as $name ) {
179 $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.
A class containing constants representing the names of configuration variables.
const AccountCreationThrottle
Name constant for the AccountCreationThrottle setting, for use with Config::get()
const PasswordAttemptThrottle
Name constant for the PasswordAttemptThrottle setting, for use with Config::get()