Index: branches/wmf/1.17wmf1/includes/specials/SpecialUserlogin.php |
— | — | @@ -431,7 +431,7 @@ |
432 | 432 | * creation. |
433 | 433 | */ |
434 | 434 | public function authenticateUserData() { |
435 | | - global $wgUser, $wgAuth, $wgMemc; |
| 435 | + global $wgUser, $wgAuth; |
436 | 436 | |
437 | 437 | if ( $this->mName == '' ) { |
438 | 438 | return self::NO_NAME; |
— | — | @@ -452,22 +452,9 @@ |
453 | 453 | return self::NEED_TOKEN; |
454 | 454 | } |
455 | 455 | |
456 | | - global $wgPasswordAttemptThrottle; |
457 | | - |
458 | | - $throttleCount = 0; |
459 | | - if ( is_array( $wgPasswordAttemptThrottle ) ) { |
460 | | - $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName ) ); |
461 | | - $count = $wgPasswordAttemptThrottle['count']; |
462 | | - $period = $wgPasswordAttemptThrottle['seconds']; |
463 | | - |
464 | | - $throttleCount = $wgMemc->get( $throttleKey ); |
465 | | - if ( !$throttleCount ) { |
466 | | - $wgMemc->add( $throttleKey, 1, $period ); // start counter |
467 | | - } elseif ( $throttleCount < $count ) { |
468 | | - $wgMemc->incr( $throttleKey ); |
469 | | - } elseif ( $throttleCount >= $count ) { |
470 | | - return self::THROTTLED; |
471 | | - } |
| 456 | + $throttleCount = self::incLoginThrottle( $this->mName ); |
| 457 | + if ( $throttleCount === true ) { |
| 458 | + return self::THROTTLED; |
472 | 459 | } |
473 | 460 | |
474 | 461 | // Validate the login token |
— | — | @@ -561,8 +548,8 @@ |
562 | 549 | $wgUser = $u; |
563 | 550 | |
564 | 551 | // Please reset throttle for successful logins, thanks! |
565 | | - if( $throttleCount ) { |
566 | | - $wgMemc->delete( $throttleKey ); |
| 552 | + if ( $throttleCount ) { |
| 553 | + self::clearLoginThrottle( $this->mName ); |
567 | 554 | } |
568 | 555 | |
569 | 556 | if ( $isAutoCreated ) { |
— | — | @@ -576,6 +563,46 @@ |
577 | 564 | return $retval; |
578 | 565 | } |
579 | 566 | |
| 567 | + /* |
| 568 | + * Increment the login attempt throttle hit count for the (username,current IP) |
| 569 | + * tuple unless the throttle was already reached. |
| 570 | + * @param $username string The user name |
| 571 | + * @return Bool|Integer The integer hit count or True if it is already at the limit |
| 572 | + */ |
| 573 | + public static function incLoginThrottle( $username ) { |
| 574 | + global $wgPasswordAttemptThrottle, $wgMemc; |
| 575 | + |
| 576 | + $throttleCount = 0; |
| 577 | + if ( is_array( $wgPasswordAttemptThrottle ) ) { |
| 578 | + $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $username ) ); |
| 579 | + $count = $wgPasswordAttemptThrottle['count']; |
| 580 | + $period = $wgPasswordAttemptThrottle['seconds']; |
| 581 | + |
| 582 | + $throttleCount = $wgMemc->get( $throttleKey ); |
| 583 | + if ( !$throttleCount ) { |
| 584 | + $wgMemc->add( $throttleKey, 1, $period ); // start counter |
| 585 | + } elseif ( $throttleCount < $count ) { |
| 586 | + $wgMemc->incr( $throttleKey ); |
| 587 | + } elseif ( $throttleCount >= $count ) { |
| 588 | + return true; |
| 589 | + } |
| 590 | + } |
| 591 | + |
| 592 | + return $throttleCount; |
| 593 | + } |
| 594 | + |
| 595 | + /* |
| 596 | + * Clear the login attempt throttle hit count for the (username,current IP) tuple. |
| 597 | + * @param $username string The user name |
| 598 | + * @return void |
| 599 | + */ |
| 600 | + public static function clearLoginThrottle( $username ) { |
| 601 | + global $wgMemc; |
| 602 | + |
| 603 | + $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $username ) ); |
| 604 | + $wgMemc->delete( $throttleKey ); |
| 605 | + } |
| 606 | + |
580 | 607 | /** |
581 | 608 | * Attempt to automatically create a user on login. Only succeeds if there |
582 | 609 | * is an external authentication method which allows it. |
— | — | @@ -872,11 +899,11 @@ |
873 | 900 | global $wgUser; |
874 | 901 | # Run any hooks; display injected HTML |
875 | 902 | $injected_html = ''; |
876 | | - $welcome_creation_msg = 'welcomecreation'; |
| 903 | + $welcome_creation_msg = 'welcomecreation'; |
877 | 904 | wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$injected_html ) ); |
878 | 905 | |
879 | 906 | //let any extensions change what message is shown |
880 | | - wfRunHooks( 'BeforeWelcomeCreation', array( &$welcome_creation_msg, &$injected_html ) ); |
| 907 | + wfRunHooks( 'BeforeWelcomeCreation', array( &$welcome_creation_msg, &$injected_html ) ); |
881 | 908 | |
882 | 909 | $this->displaySuccessfulLogin( $welcome_creation_msg, $injected_html ); |
883 | 910 | } |
Index: branches/wmf/1.17wmf1/includes/specials/SpecialResetpass.php |
— | — | @@ -208,11 +208,21 @@ |
209 | 209 | throw new PasswordError( wfMsg( 'badretype' ) ); |
210 | 210 | } |
211 | 211 | |
| 212 | + $throttleCount = LoginForm::incLoginThrottle( $this->mUserName ); |
| 213 | + if ( $throttleCount === true ) { |
| 214 | + throw new PasswordError( wfMsg( 'login-throttled' ) ); |
| 215 | + } |
| 216 | + |
212 | 217 | if( !$user->checkTemporaryPassword($this->mOldpass) && !$user->checkPassword($this->mOldpass) ) { |
213 | 218 | wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'wrongpassword' ) ); |
214 | 219 | throw new PasswordError( wfMsg( 'resetpass-wrong-oldpass' ) ); |
215 | 220 | } |
216 | | - |
| 221 | + |
| 222 | + // Please reset throttle for successful logins, thanks! |
| 223 | + if ( $throttleCount ) { |
| 224 | + LoginForm::clearLoginThrottle( $this->mUserName ); |
| 225 | + } |
| 226 | + |
217 | 227 | try { |
218 | 228 | $user->setPassword( $this->mNewpass ); |
219 | 229 | wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'success' ) ); |