r38886 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38885‎ | r38886 | r38887 >
Date:11:49, 8 August 2008
Author:werdna
Status:old
Tags:
Comment:
* (bug 12370) Add throttle on password attempts. Defaults to max 5 attempts in 5 minutes.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUserlogin.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DefaultSettings.php
@@ -3357,3 +3357,9 @@
33583358 * ting this variable false.
33593359 */
33603360 $wgUseAutomaticEditSummaries = true;
 3361+
 3362+/**
 3363+ * Limit password attempts to X attempts per Y seconds per IP per account.
 3364+ * Requires memcached.
 3365+ */
 3366+$wgPasswordAttemptThrottle = array( 5, 300 );
\ No newline at end of file
Index: trunk/phase3/includes/specials/SpecialUserlogin.php
@@ -33,6 +33,7 @@
3434 const RESET_PASS = 7;
3535 const ABORTED = 8;
3636 const CREATE_BLOCKED = 9;
 37+ const THROTTLED = 10;
3738
3839 var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
3940 var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
@@ -372,6 +373,23 @@
373374 if ( '' == $this->mName ) {
374375 return self::NO_NAME;
375376 }
 377+
 378+ global $wgPasswordAttemptThrottle;
 379+ if (is_array($wgPasswordAttemptThrottle) && count($wgPasswordAttemptThrottle) >=2) {
 380+ list($count,$period) = $wgPasswordAttemptThrottle;
 381+ $key = wfMemcKey( 'password-throttle', wfGetIP(), $this->mName );
 382+
 383+ global $wgMemc;
 384+ $cur = $wgMemc->get($key);
 385+ if ($cur>0 && $cur<$count) {
 386+ $wgMemc->incr($key);
 387+ // Okay
 388+ } elseif ($cur>0) {
 389+ return self::THROTTLED;
 390+ } elseif (!$cur) {
 391+ $wgMemc->add( $key, 1, $period );
 392+ }
 393+ }
376394
377395 // Load $wgUser now, and check to see if we're logging in as the same name.
378396 // This is necessary because loading $wgUser (say by calling getName()) calls
@@ -541,6 +559,9 @@
542560 case self::CREATE_BLOCKED:
543561 $this->userBlockedMessage();
544562 break;
 563+ case self::THROTTLED:
 564+ $this->mainLoginForm( wfMsg( 'login-throttled' ) );
 565+ break;
545566 default:
546567 throw new MWException( "Unhandled case value" );
547568 }
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -971,6 +971,7 @@
972972 You should log in and change your password now.
973973
974974 You may ignore this message, if this account was created in error.',
 975+'login-throttled' => "You have made too many recent attempts on this account's password. Please wait before trying again.",
975976 'loginlanguagelabel' => 'Language: $1',
976977 'loginlanguagelinks' => '* Deutsch|de
977978 * English|en
Index: trunk/phase3/RELEASE-NOTES
@@ -79,6 +79,7 @@
8080 * (bug 15055) Talk page notifications no longer attempt to send mail when
8181 user's e-mail address is invalid or unconfirmed
8282 * (bug 2443) Add image name as alt-text when no caption is provided.
 83+* (bug 12370) Add throttle on password attempts. Defaults to max 5 attempts in 5 minutes.
8384
8485 === API changes in 1.14 ===
8586

Follow-up revisions

RevisionCommit summaryAuthorDate
r38960Cleanup for r38886 "(bug 12370) Add throttle on password attempts. Defaults t...brion22:15, 8 August 2008

Status & tagging log