reset password attempt throttle at successful logins
authorDomas Mituzas <midom@users.mediawiki.org>
Fri, 24 Oct 2008 09:07:43 +0000 (09:07 +0000)
committerDomas Mituzas <midom@users.mediawiki.org>
Fri, 24 Oct 2008 09:07:43 +0000 (09:07 +0000)
includes/specials/SpecialUserlogin.php

index 72c5ba9..813cf46 100644 (file)
@@ -379,18 +379,20 @@ class LoginForm {
                }
                
                global $wgPasswordAttemptThrottle;
+
+               $throttleCount=0;
                if ( is_array($wgPasswordAttemptThrottle) ) {
-                       $key = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName ) );
+                       $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName ) );
                        $count = $wgPasswordAttemptThrottle['count'];
                        $period = $wgPasswordAttemptThrottle['seconds'];
                        
                        global $wgMemc;
-                       $cur = $wgMemc->get($key);
-                       if ( !$cur ) {
-                               $wgMemc->add( $key, 1, $period ); // start counter
-                       } else if ( $cur < $count ) {
-                               $wgMemc->incr($key);
-                       } else if ( $cur >= $count ) {
+                       $throttleCount = $wgMemc->get($throttleKey);
+                       if ( !$throttleCount ) {
+                               $wgMemc->add( $throttleKey, 1, $period ); // start counter
+                       } else if ( $throttleCount < $count ) {
+                               $wgMemc->incr($throttleKey);
+                       } else if ( $throttleCount >= $count ) {
                                return self::THROTTLED;
                        }
                }
@@ -462,6 +464,11 @@ class LoginForm {
                        $wgAuth->updateUser( $u );
                        $wgUser = $u;
 
+                       // Please reset throttle for successful logins, thanks!
+                       if($throttleCount) {
+                               $wgMemc->delete($throttleKey);
+                       }
+
                        if ( $isAutoCreated ) {
                                // Must be run after $wgUser is set, for correct new user log
                                wfRunHooks( 'AuthPluginAutoCreate', array( $wgUser ) );