42 $this->throttleSettings = array_intersect_key( $params,
43 [
'accountCreationThrottle' =>
true,
'passwordAttemptThrottle' =>
true ] );
45 $this->cache = $params[
'cache'] ?? $services->getObjectCacheFactory()
46 ->getLocalClusterInstance();
60 $this->throttleSettings += [
63 'passwordAttemptThrottle' =>
67 if ( !empty( $this->throttleSettings[
'accountCreationThrottle'] ) ) {
68 $this->accountCreationThrottle =
new Throttler(
69 $this->throttleSettings[
'accountCreationThrottle'], [
70 'type' =>
'acctcreate',
71 'cache' => $this->cache,
75 if ( !empty( $this->throttleSettings[
'passwordAttemptThrottle'] ) ) {
76 $this->passwordAttemptThrottle =
new Throttler(
77 $this->throttleSettings[
'passwordAttemptThrottle'], [
79 'cache' => $this->cache,
87 if ( !$this->accountCreationThrottle || !$creator->isPingLimitable() ) {
88 return \StatusValue::newGood();
91 $ip = $this->manager->getRequest()->getIP();
93 if ( !$this->
getHookRunner()->onExemptFromAccountCreationThrottle( $ip ) ) {
94 $this->logger->debug( __METHOD__ .
": a hook allowed account creation w/o throttle" );
95 return \StatusValue::newGood();
98 $result = $this->accountCreationThrottle->increase(
null, $ip, __METHOD__ );
100 $message =
wfMessage(
'acct_creation_throttle_hit' )->params( $result[
'count'] )
101 ->durationParams( $result[
'wait'] );
102 return \StatusValue::newFatal( $message );
105 return \StatusValue::newGood();
110 if ( !$this->passwordAttemptThrottle ) {
111 return \StatusValue::newGood();
114 $ip = $this->manager->getRequest()->getIP();
117 }
catch ( \UnexpectedValueException ) {
123 if ( $username !==
null ) {
124 $usernames = $this->manager->normalizeUsername( $username );
126 $usernames = [ null ];
129 foreach ( $usernames as $name ) {
130 $r = $this->passwordAttemptThrottle->increase( $name, $ip, __METHOD__ );
131 if ( $r && ( !$result || $result[
'wait'] < $r[
'wait'] ) ) {
137 $message =
wfMessage(
'login-throttled' )->durationParams( $result[
'wait'] );
138 return \StatusValue::newFatal( $message );
140 $this->manager->setAuthenticationSessionData(
'LoginThrottle',
141 [
'users' => $usernames,
'ip' => $ip ] );
142 return \StatusValue::newGood();
153 } elseif ( !$this->passwordAttemptThrottle ) {
157 $data = $this->manager->getAuthenticationSessionData(
'LoginThrottle' );
161 $this->logger->info(
'throttler data not found for {user}', [
'user' => $user->getName() ] );
165 foreach ( $data[
'users'] as $name ) {
166 $this->passwordAttemptThrottle->clear( $name, $data[
'ip'] );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
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()