MediaWiki  1.27.1
PasswordPolicyChecks.php
Go to the documentation of this file.
1 <?php
23 use \Cdb\Reader as CdbReader;
24 
30 
38  public static function checkMinimalPasswordLength( $policyVal, User $user, $password ) {
40  if ( $policyVal > strlen( $password ) ) {
41  $status->error( 'passwordtooshort', $policyVal );
42  }
43  return $status;
44  }
45 
53  public static function checkMinimumPasswordLengthToLogin( $policyVal, User $user, $password ) {
55  if ( $policyVal > strlen( $password ) ) {
56  $status->fatal( 'passwordtooshort', $policyVal );
57  }
58  return $status;
59  }
60 
68  public static function checkMaximalPasswordLength( $policyVal, User $user, $password ) {
70  if ( $policyVal < strlen( $password ) ) {
71  $status->fatal( 'passwordtoolong', $policyVal );
72  }
73  return $status;
74  }
75 
83  public static function checkPasswordCannotMatchUsername( $policyVal, User $user, $password ) {
86  $username = $user->getName();
87  if ( $policyVal && $wgContLang->lc( $password ) === $wgContLang->lc( $username ) ) {
88  $status->error( 'password-name-match' );
89  }
90  return $status;
91  }
92 
100  public static function checkPasswordCannotMatchBlacklist( $policyVal, User $user, $password ) {
101  static $blockedLogins = [
102  'Useruser' => 'Passpass', 'Useruser1' => 'Passpass1', # r75589
103  'Apitestsysop' => 'testpass', 'Apitestuser' => 'testpass' # r75605
104  ];
105 
107  $username = $user->getName();
108  if ( $policyVal ) {
109  if ( isset( $blockedLogins[$username] ) && $password == $blockedLogins[$username] ) {
110  $status->error( 'password-login-forbidden' );
111  }
112 
113  // Example from ApiChangeAuthenticationRequest
114  if ( $password === 'ExamplePassword' ) {
115  $status->error( 'password-login-forbidden' );
116  }
117  }
118  return $status;
119  }
120 
132  public static function checkPopularPasswordBlacklist( $policyVal, User $user, $password ) {
133  global $wgPopularPasswordFile, $wgSitename;
135  if ( $policyVal > 0 ) {
136  $langEn = Language::factory( 'en' );
137  $passwordKey = $langEn->lc( trim( $password ) );
138 
139  // People often use the name of the current site, which won't be
140  // in the common password file. Also check '' for people who use
141  // just whitespace.
142  $sitename = $langEn->lc( trim( $wgSitename ) );
143  $hardcodedCommonPasswords = [ '', 'wiki', 'mediawiki', $sitename ];
144  if ( in_array( $passwordKey, $hardcodedCommonPasswords ) ) {
145  $status->error( 'passwordtoopopular' );
146  return $status;
147  }
148 
149  // This could throw an exception, but there's not a good way
150  // of failing gracefully, if say the file is missing, so just
151  // let the exception fall through.
152  // Format of cdb file is mapping password => popularity rank.
153  // See maintenance/createCommonPasswordCdb.php
154  $db = CdbReader::open( $wgPopularPasswordFile );
155 
156  $res = $db->get( $passwordKey );
157  if ( $res && (int)$res <= $policyVal ) {
158  // Note: If you want to find the true number of common
159  // passwords stored (for reporting the error), you have to take
160  // the max of the policyVal and $db->get( '_TOTALENTRIES' ).
161  $status->error( 'passwordtoopopular' );
162  }
163  }
164  return $status;
165  }
166 
167 }
static checkMinimalPasswordLength($policyVal, User $user, $password)
Check password is longer than minimum, not fatal.
$wgSitename
Name of the site.
static checkPasswordCannotMatchBlacklist($policyVal, User $user, $password)
Check if username and password are on a blacklist.
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
getName()
Get the user name, or the IP of an anonymous user.
Definition: User.php:2088
Functions to check passwords against a policy requirement.
$res
Definition: database.txt:21
static checkPopularPasswordBlacklist($policyVal, User $user, $password)
Ensure that password isn't in top X most popular passwords.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:762
static checkPasswordCannotMatchUsername($policyVal, User $user, $password)
Check if username and password match.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition: design.txt:56
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1004
static factory($code)
Get a cached or new language object for a given language code.
Definition: Language.php:179
static checkMaximalPasswordLength($policyVal, User $user, $password)
Check password is shorter than maximum, fatal.
static newGood($value=null)
Factory function for good results.
Definition: Status.php:101
static checkMinimumPasswordLengthToLogin($policyVal, User $user, $password)
Check password is longer than minimum, fatal.