From: Brad Jorsch Date: Thu, 1 Dec 2016 23:30:23 +0000 (-0500) Subject: Remove $purpose parameter from password validity check X-Git-Tag: 1.31.0-rc.0~4695 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=5840c440ce414d72eef1d384383413942a55fe8e Remove $purpose parameter from password validity check This was added in I56b6600 in an attempt to work around a bug in CentralAuth, but the bug has since been fixed in a better way. No hook functions in Gerrit use the parameter (or ever have, as far as I can tell), and anything that was passing a value other than the default 'login' has since been removed. So let's just get rid of it instead of keeping it around doing nothing. Change-Id: Ie604e03d268706221161ac93eb866f477e466fb4 --- diff --git a/docs/hooks.txt b/docs/hooks.txt index a73d50f9bd..da12d8c367 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -2554,8 +2554,6 @@ $user: the User considering the edit 'PasswordPoliciesForUser': Alter the effective password policy for a user. $user: User object whose policy you are modifying &$effectivePolicy: Array of policy statements that apply to this user -$purpose: string indicating purpose of the check, one of 'login', 'create', - or 'reset' 'PerformRetroactiveAutoblock': Called before a retroactive autoblock is applied to a user. diff --git a/includes/password/UserPasswordPolicy.php b/includes/password/UserPasswordPolicy.php index 5584f6f162..bf1f8acfb7 100644 --- a/includes/password/UserPasswordPolicy.php +++ b/includes/password/UserPasswordPolicy.php @@ -67,12 +67,11 @@ class UserPasswordPolicy { * Check if a passwords meets the effective password policy for a User. * @param User $user who's policy we are checking * @param string $password the password to check - * @param string $purpose one of 'login', 'create', 'reset' * @return Status error to indicate the password didn't meet the policy, or fatal to * indicate the user shouldn't be allowed to login. */ - public function checkUserPassword( User $user, $password, $purpose = 'login' ) { - $effectivePolicy = $this->getPoliciesForUser( $user, $purpose ); + public function checkUserPassword( User $user, $password ) { + $effectivePolicy = $this->getPoliciesForUser( $user ); return $this->checkPolicies( $user, $password, @@ -134,20 +133,16 @@ class UserPasswordPolicy { * Get the policy for a user, based on their group membership. Public so * UI elements can access and inform the user. * @param User $user - * @param string $purpose one of 'login', 'create', 'reset' * @return array the effective policy for $user */ - public function getPoliciesForUser( User $user, $purpose = 'login' ) { - $effectivePolicy = $this->policies['default']; - if ( $purpose !== 'create' ) { - $effectivePolicy = self::getPoliciesForGroups( - $this->policies, - $user->getEffectiveGroups(), - $this->policies['default'] - ); - } + public function getPoliciesForUser( User $user ) { + $effectivePolicy = self::getPoliciesForGroups( + $this->policies, + $user->getEffectiveGroups(), + $this->policies['default'] + ); - Hooks::run( 'PasswordPoliciesForUser', [ $user, &$effectivePolicy, $purpose ] ); + Hooks::run( 'PasswordPoliciesForUser', [ $user, &$effectivePolicy ] ); return $effectivePolicy; } diff --git a/includes/user/User.php b/includes/user/User.php index f07db0e1b7..26f10407a3 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -1003,11 +1003,10 @@ class User implements IDBAccessObject { * able to set their password to this. * * @param string $password Desired password - * @param string $purpose one of 'login', 'create', 'reset' * @return Status * @since 1.23 */ - public function checkPasswordValidity( $password, $purpose = 'login' ) { + public function checkPasswordValidity( $password ) { global $wgPasswordPolicy; $upp = new UserPasswordPolicy( @@ -1024,7 +1023,7 @@ class User implements IDBAccessObject { } if ( $result === false ) { - $status->merge( $upp->checkUserPassword( $this, $password, $purpose ) ); + $status->merge( $upp->checkUserPassword( $this, $password ) ); return $status; } elseif ( $result === true ) { return $status;