Add PasswordPolicy to check the password isn't in the large blacklist
[lhc/web/wiklou.git] / includes / password / PasswordPolicyChecks.php
index 502f1e0..04ee6e9 100644 (file)
@@ -21,6 +21,8 @@
  */
 
 use Cdb\Reader as CdbReader;
+use MediaWiki\MediaWikiServices;
+use Wikimedia\PasswordBlacklist;
 
 /**
  * Functions to check passwords against a policy requirement
@@ -81,10 +83,12 @@ class PasswordPolicyChecks {
         * @return Status error if username and password match, and policy is true
         */
        public static function checkPasswordCannotMatchUsername( $policyVal, User $user, $password ) {
-               global $wgContLang;
                $status = Status::newGood();
                $username = $user->getName();
-               if ( $policyVal && $wgContLang->lc( $password ) === $wgContLang->lc( $username ) ) {
+               $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+               if (
+                       $policyVal && $contLang->lc( $password ) === $contLang->lc( $username )
+               ) {
                        $status->error( 'password-name-match' );
                }
                return $status;
@@ -164,4 +168,25 @@ class PasswordPolicyChecks {
                return $status;
        }
 
+       /**
+        * Ensure the password isn't in the list of passwords blacklisted by the
+        * wikimedia/password-blacklist library
+        *
+        * @param bool $policyVal Whether to apply this policy
+        * @param User $user
+        * @param string $password
+        *
+        * @since 1.33
+        *
+        * @return Status
+        */
+       public static function checkPasswordNotInLargeBlacklist( $policyVal, User $user, $password ) {
+               $status = Status::newGood();
+               if ( $policyVal && PasswordBlacklist\PasswordBlacklist::isBlacklisted( $password ) ) {
+                       $status->error( 'passwordinlargeblacklist' );
+               }
+
+               return $status;
+       }
+
 }