Index: trunk/phase3/docs/hooks.txt |
— | — | @@ -864,7 +864,7 @@ |
865 | 865 | |
866 | 866 | 'isValidPassword': Override the result of User::isValidPassword() |
867 | 867 | $password: The password entered by the user |
868 | | -&$result: Set this to either true (passes) or the key for a message error |
| 868 | +&$result: Set this and return false to override the internal checks |
869 | 869 | $user: User the password is being validated for |
870 | 870 | |
871 | 871 | 'LanguageGetMagic': DEPRECATED, use $magicWords in a file listed in |
Index: trunk/phase3/includes/User.php |
— | — | @@ -619,20 +619,38 @@ |
620 | 620 | * Is the input a valid password for this user? |
621 | 621 | * |
622 | 622 | * @param $password String Desired password |
623 | | - * @return mixed: true on success, string of error message on failure |
| 623 | + * @return bool True or false |
624 | 624 | */ |
625 | 625 | function isValidPassword( $password ) { |
626 | 626 | global $wgMinimalPasswordLength, $wgContLang; |
627 | 627 | |
628 | 628 | if( !wfRunHooks( 'isValidPassword', array( $password, &$result, $this ) ) ) |
629 | 629 | return $result; |
| 630 | + if( $result === false ) |
| 631 | + return false; |
| 632 | + |
| 633 | + // Password needs to be long enough, and can't be the same as the username |
| 634 | + return strlen( $password ) >= $wgMinimalPasswordLength |
| 635 | + && $wgContLang->lc( $password ) !== $wgContLang->lc( $this->mName ); |
| 636 | + } |
630 | 637 | |
631 | | - // Password needs to be long enough |
632 | | - if( strlen( $password ) < $wgMinimalPasswordLength ) { |
633 | | - return 'passwordtooshort'; |
634 | | - } elseif( $wgContLang->lc( $password ) == $wgContLang->lc( $this->mName ) ) { |
635 | | - return 'password-name-match'; |
636 | | - } else { |
| 638 | + /** |
| 639 | + * Given unvalidated password input, return error message on failure. |
| 640 | + * |
| 641 | + * @param $password String Desired password |
| 642 | + * @return mixed: true on success, string of error message on failure |
| 643 | + */ |
| 644 | + static function getPasswordValidity( $password ) { |
| 645 | + global $wgMinimalPasswordLength, $wgContLang; |
| 646 | + |
| 647 | + if(!$this->isValidPassword( $password )) { |
| 648 | + if( strlen( $password ) < $wgMinimalPasswordLength ) { |
| 649 | + return 'passwordtooshort'; |
| 650 | + } elseif( $wgContLang->lc( $password ) == $wgContLang->lc( $this->mName ) ) { |
| 651 | + return 'password-name-match'; |
| 652 | + } |
| 653 | + } |
| 654 | + else { |
637 | 655 | return true; |
638 | 656 | } |
639 | 657 | } |
— | — | @@ -1735,13 +1753,13 @@ |
1736 | 1754 | if( !$wgAuth->allowPasswordChange() ) { |
1737 | 1755 | throw new PasswordError( wfMsg( 'password-change-forbidden' ) ); |
1738 | 1756 | } |
1739 | | - |
1740 | | - $valid = $this->isValidPassword( $str ); |
1741 | | - if( $valid !== true ) { |
1742 | | - global $wgMinimalPasswordLength; |
| 1757 | + |
| 1758 | + if( !$this->isValidPassword( $str ) ) { |
| 1759 | + global $wgMinimalPasswordLength; |
| 1760 | + $valid = $this->getPasswordValidity( $str ); |
1743 | 1761 | throw new PasswordError( wfMsgExt( $valid, array( 'parsemag' ), |
1744 | 1762 | $wgMinimalPasswordLength ) ); |
1745 | | - } |
| 1763 | + } |
1746 | 1764 | } |
1747 | 1765 | |
1748 | 1766 | if( !$wgAuth->setPassword( $this, $str ) ) { |
— | — | @@ -2720,7 +2738,7 @@ |
2721 | 2739 | // to. Certain authentication plugins do NOT want to save |
2722 | 2740 | // domain passwords in a mysql database, so we should |
2723 | 2741 | // check this (incase $wgAuth->strict() is false). |
2724 | | - if( $this->isValidPassword( $password ) !== true ) { |
| 2742 | + if( !$this->isValidPassword( $password ) ) { |
2725 | 2743 | return false; |
2726 | 2744 | } |
2727 | 2745 | |
Index: trunk/phase3/includes/specials/SpecialUserlogin.php |
— | — | @@ -283,7 +283,7 @@ |
284 | 284 | } |
285 | 285 | |
286 | 286 | # check for minimal password length |
287 | | - $valid = $u->isValidPassword( $this->mPassword ); |
| 287 | + $valid = $u->getPasswordValidity( $this->mPassword ); |
288 | 288 | if ( $valid !== true ) { |
289 | 289 | if ( !$this->mCreateaccountMail ) { |
290 | 290 | $this->mainLoginForm( wfMsgExt( $valid, array( 'parsemag' ), $wgMinimalPasswordLength ) ); |
Index: trunk/phase3/config/Installer.php |
— | — | @@ -713,7 +713,7 @@ |
714 | 714 | # Various password checks |
715 | 715 | if( $conf->SysopPass != '' ) { |
716 | 716 | if( $conf->SysopPass == $conf->SysopPass2 ) { |
717 | | - if( $u->isValidPassword( $conf->SysopPass ) !== true ) { |
| 717 | + if( !$u->isValidPassword( $conf->SysopPass ) ) { |
718 | 718 | $errs['SysopPass'] = "Bad password"; |
719 | 719 | } |
720 | 720 | } else { |