'isValidPassword': Override the result of User::isValidPassword()
$password: The password entered by the user
-&$result: Set this and return false to override the internal checks
+&$result: Set this to either true (passes) or the key for a message error
$user: User the password is being validated for
'LanguageGetMagic': Use this to define synonyms of magic words depending
/**
* Is the input a valid password for this user?
*
- * @param $password \string Desired password
- * @return \bool True or false
+ * @param $password String Desired password
+ * @return mixed: true on success, string of error message on failure
*/
function isValidPassword( $password ) {
global $wgMinimalPasswordLength, $wgContLang;
- $result = null;
if( !wfRunHooks( 'isValidPassword', array( $password, &$result, $this ) ) )
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 );
+ // Password needs to be long enough
+ if( strlen( $password ) < $wgMinimalPasswordLength ) {
+ return 'passwordtooshort';
+ } elseif( $wgContLang->lc( $password ) == $wgContLang->lc( $this->mName ) ) {
+ return 'password-name-match';
+ } else {
+ return true;
+ }
}
/**
throw new PasswordError( wfMsg( 'password-change-forbidden' ) );
}
- if( !$this->isValidPassword( $str ) ) {
+ $valid = $this->isValidPassword( $str );
+ if( $valid !== true ) {
global $wgMinimalPasswordLength;
- throw new PasswordError( wfMsgExt( 'passwordtooshort', array( 'parsemag' ),
+ throw new PasswordError( wfMsgExt( $valid, array( 'parsemag' ),
$wgMinimalPasswordLength ) );
}
}
// to. Certain authentication plugins do NOT want to save
// domain passwords in a mysql database, so we should
// check this (incase $wgAuth->strict() is false).
- if( !$this->isValidPassword( $password ) ) {
+ if( $this->isValidPassword( $password ) !== true ) {
return false;
}
}
# check for minimal password length
- if ( !$u->isValidPassword( $this->mPassword ) ) {
+ $valid = $u->isValidPassword( $this->mPassword );
+ if ( $valid !== true ) {
if ( !$this->mCreateaccountMail ) {
- $this->mainLoginForm( wfMsgExt( 'passwordtooshort', array( 'parsemag' ), $wgMinimalPasswordLength ) );
+ $this->mainLoginForm( wfMsgExt( $valid, array( 'parsemag' ), $wgMinimalPasswordLength ) );
return false;
} else {
# do not force a password for account creation by email
Please try again.',
'wrongpasswordempty' => 'Password entered was blank.
Please try again.',
-'passwordtooshort' => 'Your password is invalid or too short.
-It must have at least {{PLURAL:$1|1 character|$1 characters}} and be different from your username.',
+'passwordtooshort' => 'Your password is too short.
+It must have at least {{PLURAL:$1|1 character|$1 characters}}.',
+'password-name-match' => 'Your password must be different from your username.',
'mailmypassword' => 'E-mail new password',
'passwordremindertitle' => 'New temporary password for {{SITENAME}}',
'passwordremindertext' => 'Someone (probably you, from IP address $1) requested a new