Index: trunk/phase3/maintenance/createAndPromote.php |
— | — | @@ -36,9 +36,14 @@ |
37 | 37 | die( 1 ); |
38 | 38 | } |
39 | 39 | |
| 40 | +try { |
| 41 | + $user->setPassword( $password ); |
| 42 | +} catch( PasswordError $pwe ) { |
| 43 | + $this->error( $pwe->getText(), true ); |
| 44 | +} |
| 45 | + |
40 | 46 | # Insert the account into the database |
41 | 47 | $user->addToDatabase(); |
42 | | -$user->setPassword( $password ); |
43 | 48 | $user->saveSettings(); |
44 | 49 | |
45 | 50 | # Promote user |
Index: trunk/phase3/maintenance/language/messages.inc |
— | — | @@ -422,6 +422,7 @@ |
423 | 423 | 'wrongpassword', |
424 | 424 | 'wrongpasswordempty', |
425 | 425 | 'passwordtooshort', |
| 426 | + 'password-name-match', |
426 | 427 | 'mailmypassword', |
427 | 428 | 'passwordremindertitle', |
428 | 429 | 'passwordremindertext', |
Index: trunk/phase3/docs/hooks.txt |
— | — | @@ -830,7 +830,7 @@ |
831 | 831 | |
832 | 832 | 'isValidPassword': Override the result of User::isValidPassword() |
833 | 833 | $password: The password entered by the user |
834 | | -&$result: Set this and return false to override the internal checks |
| 834 | +&$result: Set this to either true (passes) or the key for a message error |
835 | 835 | $user: User the password is being validated for |
836 | 836 | |
837 | 837 | 'LanguageGetMagic': Use this to define synonyms of magic words depending |
Index: trunk/phase3/includes/User.php |
— | — | @@ -616,21 +616,23 @@ |
617 | 617 | /** |
618 | 618 | * Is the input a valid password for this user? |
619 | 619 | * |
620 | | - * @param $password \string Desired password |
621 | | - * @return \bool True or false |
| 620 | + * @param $password String Desired password |
| 621 | + * @return mixed: true on success, string of error message on failure |
622 | 622 | */ |
623 | 623 | function isValidPassword( $password ) { |
624 | 624 | global $wgMinimalPasswordLength, $wgContLang; |
625 | 625 | |
626 | | - $result = null; |
627 | 626 | if( !wfRunHooks( 'isValidPassword', array( $password, &$result, $this ) ) ) |
628 | 627 | return $result; |
629 | | - if( $result === false ) |
630 | | - return false; |
631 | 628 | |
632 | | - // Password needs to be long enough, and can't be the same as the username |
633 | | - return strlen( $password ) >= $wgMinimalPasswordLength |
634 | | - && $wgContLang->lc( $password ) !== $wgContLang->lc( $this->mName ); |
| 629 | + // Password needs to be long enough |
| 630 | + if( strlen( $password ) < $wgMinimalPasswordLength ) { |
| 631 | + return 'passwordtooshort'; |
| 632 | + } elseif( $wgContLang->lc( $password ) == $wgContLang->lc( $this->mName ) ) { |
| 633 | + return 'password-name-match'; |
| 634 | + } else { |
| 635 | + return true; |
| 636 | + } |
635 | 637 | } |
636 | 638 | |
637 | 639 | /** |
— | — | @@ -1714,9 +1716,10 @@ |
1715 | 1717 | throw new PasswordError( wfMsg( 'password-change-forbidden' ) ); |
1716 | 1718 | } |
1717 | 1719 | |
1718 | | - if( !$this->isValidPassword( $str ) ) { |
| 1720 | + $valid = $this->isValidPassword( $str ); |
| 1721 | + if( $valid !== true ) { |
1719 | 1722 | global $wgMinimalPasswordLength; |
1720 | | - throw new PasswordError( wfMsgExt( 'passwordtooshort', array( 'parsemag' ), |
| 1723 | + throw new PasswordError( wfMsgExt( $valid, array( 'parsemag' ), |
1721 | 1724 | $wgMinimalPasswordLength ) ); |
1722 | 1725 | } |
1723 | 1726 | } |
— | — | @@ -2725,7 +2728,7 @@ |
2726 | 2729 | // to. Certain authentication plugins do NOT want to save |
2727 | 2730 | // domain passwords in a mysql database, so we should |
2728 | 2731 | // check this (incase $wgAuth->strict() is false). |
2729 | | - if( !$this->isValidPassword( $password ) ) { |
| 2732 | + if( $this->isValidPassword( $password ) !== true ) { |
2730 | 2733 | return false; |
2731 | 2734 | } |
2732 | 2735 | |
Index: trunk/phase3/includes/specials/SpecialUserlogin.php |
— | — | @@ -277,9 +277,10 @@ |
278 | 278 | } |
279 | 279 | |
280 | 280 | # check for minimal password length |
281 | | - if ( !$u->isValidPassword( $this->mPassword ) ) { |
| 281 | + $valid = $u->isValidPassword( $this->mPassword ); |
| 282 | + if ( $valid !== true ) { |
282 | 283 | if ( !$this->mCreateaccountMail ) { |
283 | | - $this->mainLoginForm( wfMsgExt( 'passwordtooshort', array( 'parsemag' ), $wgMinimalPasswordLength ) ); |
| 284 | + $this->mainLoginForm( wfMsgExt( $valid, array( 'parsemag' ), $wgMinimalPasswordLength ) ); |
284 | 285 | return false; |
285 | 286 | } else { |
286 | 287 | # do not force a password for account creation by email |
Index: trunk/phase3/config/index.php |
— | — | @@ -702,7 +702,7 @@ |
703 | 703 | # Various password checks |
704 | 704 | if( $conf->SysopPass != '' ) { |
705 | 705 | if( $conf->SysopPass == $conf->SysopPass2 ) { |
706 | | - if( !$u->isValidPassword( $conf->SysopPass ) ) { |
| 706 | + if( $u->isValidPassword( $conf->SysopPass ) !== true ) { |
707 | 707 | $errs['SysopPass'] = "Bad password"; |
708 | 708 | } |
709 | 709 | } else { |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -956,8 +956,9 @@ |
957 | 957 | Please try again.', |
958 | 958 | 'wrongpasswordempty' => 'Password entered was blank. |
959 | 959 | Please try again.', |
960 | | -'passwordtooshort' => 'Your password is invalid or too short. |
961 | | -It must have at least {{PLURAL:$1|1 character|$1 characters}} and be different from your username.', |
| 960 | +'passwordtooshort' => 'Your password is too short. |
| 961 | +It must have at least {{PLURAL:$1|1 character|$1 characters}}.', |
| 962 | +'password-name-match' => 'Your password must be different from your username.', |
962 | 963 | 'mailmypassword' => 'E-mail new password', |
963 | 964 | 'passwordremindertitle' => 'New temporary password for {{SITENAME}}', |
964 | 965 | 'passwordremindertext' => 'Someone (probably you, from IP address $1) requested a new |