Add PasswordPolicy to check the password isn't in the large blacklist
[lhc/web/wiklou.git] / includes / password / PasswordPolicyChecks.php
index 837e959..04ee6e9 100644 (file)
@@ -22,6 +22,7 @@
 
 use Cdb\Reader as CdbReader;
 use MediaWiki\MediaWikiServices;
+use Wikimedia\PasswordBlacklist;
 
 /**
  * Functions to check passwords against a policy requirement
@@ -167,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;
+       }
+
 }