* Clean up User::isValidPassword()
authorRob Church <robchurch@users.mediawiki.org>
Tue, 17 Jul 2007 16:44:40 +0000 (16:44 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Tue, 17 Jul 2007 16:44:40 +0000 (16:44 +0000)
* Document 'isValidPassword' hook

docs/hooks.txt
includes/User.php

index ca30f73..9ad6b9f 100644 (file)
@@ -464,6 +464,10 @@ after noinclude/includeonly/onlyinclude and other processing.
 &$text: string containing partially parsed text
 &$this->mStripState: Parser's internal StripState object
 
+'isValidPassword': Override the result of User::isValidPassword()
+$password: Desired password
+&$result: Set this and return false to override the internal checks
+
 'LoginAuthenticateAudit': a login attempt for a valid user account either succeeded or failed.
                           No return data is accepted; this hook is for auditing only.
 $user: the User object being authenticated against
index d96cc6b..b39f24f 100644 (file)
@@ -481,19 +481,23 @@ class User {
        }
 
        /**
-        * Is the input a valid password?
+        * Is the input a valid password for this user?
         *
-        * @param string $password
+        * @param string $password Desired password
         * @return bool
         */
        function isValidPassword( $password ) {
                global $wgMinimalPasswordLength, $wgContLang;
 
                $result = null;
-               if( !wfRunHooks( 'isValidPassword', array( $password, &$result ) ) ) return $result;
-               if ($result === false) return false;
-               return (strlen( $password ) >= $wgMinimalPasswordLength) &&
-                       ($wgContLang->lc( $password ) !== $wgContLang->lc( $this->mName ));
+               if( !wfRunHooks( 'isValidPassword', array( $password, &$result ) ) )
+                       return $result;
+               if( $result === false )
+                       return $false;
+                       
+               // Password needs to be long enough, and can't be the same as the username
+               return strlen( $password ) >= $wgMinimalPasswordLength
+                       && $wgContLang->lc( $password ) !== $wgContLang->lc( $this->mName );
        }
 
        /**