59 $this->throttleSettings = array_intersect_key( $params,
60 [
'accountCreationThrottle' =>
true,
'passwordAttemptThrottle' =>
true ] );
61 $this->cache = $params[
'cache'] ?? \ObjectCache::getLocalClusterInstance();
77 $this->throttleSettings += [
80 'passwordAttemptThrottle' => $this->config->get(
'PasswordAttemptThrottle' ),
83 if ( !empty( $this->throttleSettings[
'accountCreationThrottle'] ) ) {
84 $this->accountCreationThrottle =
new Throttler(
85 $this->throttleSettings[
'accountCreationThrottle'], [
86 'type' =>
'acctcreate',
87 'cache' => $this->cache,
91 if ( !empty( $this->throttleSettings[
'passwordAttemptThrottle'] ) ) {
92 $this->passwordAttemptThrottle =
new Throttler(
93 $this->throttleSettings[
'passwordAttemptThrottle'], [
95 'cache' => $this->cache,
102 if ( !$this->accountCreationThrottle || !$creator->isPingLimitable() ) {
103 return \StatusValue::newGood();
106 $ip = $this->manager->getRequest()->getIP();
108 if ( !$this->
getHookRunner()->onExemptFromAccountCreationThrottle( $ip ) ) {
109 $this->logger->debug( __METHOD__ .
": a hook allowed account creation w/o throttle" );
110 return \StatusValue::newGood();
113 $result = $this->accountCreationThrottle->increase(
null, $ip, __METHOD__ );
115 $message =
wfMessage(
'acct_creation_throttle_hit' )->params( $result[
'count'] )
116 ->durationParams( $result[
'wait'] );
117 return \StatusValue::newFatal( $message );
120 return \StatusValue::newGood();
124 if ( !$this->passwordAttemptThrottle ) {
125 return \StatusValue::newGood();
128 $ip = $this->manager->getRequest()->getIP();
131 }
catch ( \UnexpectedValueException $e ) {
137 $usernames = $this->manager->normalizeUsername( $username );
139 foreach ( $usernames as $name ) {
140 $r = $this->passwordAttemptThrottle->increase( $name, $ip, __METHOD__ );
141 if ( $r && ( !$result || $result[
'wait'] < $r[
'wait'] ) ) {
147 $message =
wfMessage(
'login-throttled' )->durationParams( $result[
'wait'] );
148 return \StatusValue::newFatal( $message );
150 $this->manager->setAuthenticationSessionData(
'LoginThrottle',
151 [
'users' => $usernames,
'ip' => $ip ] );
152 return \StatusValue::newGood();
163 } elseif ( !$this->passwordAttemptThrottle ) {
167 $data = $this->manager->getAuthenticationSessionData(
'LoginThrottle' );
171 $this->logger->info(
'throttler data not found for {user}', [
'user' => $user->getName() ] );
175 foreach ( $data[
'users'] as $name ) {
176 $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.
Interface for configuration instances.