MediaWiki  1.29.2
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 }
PasswordPolicyChecks\checkMinimalPasswordLength
static checkMinimalPasswordLength( $policyVal, User $user, $password)
Check password is longer than minimum, not fatal.
Definition: PasswordPolicyChecks.php:38
$status
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup 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:1049
$user
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 account $user
Definition: hooks.txt:246
$res
$res
Definition: database.txt:21
Makefile.open
open
Definition: Makefile.py:18
PasswordPolicyChecks\checkPasswordCannotMatchBlacklist
static checkPasswordCannotMatchBlacklist( $policyVal, User $user, $password)
Check if username and password are on a blacklist.
Definition: PasswordPolicyChecks.php:100
PasswordPolicyChecks\checkPasswordCannotMatchUsername
static checkPasswordCannotMatchUsername( $policyVal, User $user, $password)
Check if username and password match.
Definition: PasswordPolicyChecks.php:83
php
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
PasswordPolicyChecks\checkMinimumPasswordLengthToLogin
static checkMinimumPasswordLengthToLogin( $policyVal, User $user, $password)
Check password is longer than minimum, fatal.
Definition: PasswordPolicyChecks.php:53
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:76
$wgSitename
$wgSitename
Name of the site.
Definition: DefaultSettings.php:83
CdbReader
Definition: CdbCompat.php:31
as
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
PasswordPolicyChecks\checkMaximalPasswordLength
static checkMaximalPasswordLength( $policyVal, User $user, $password)
Check password is shorter than maximum, fatal.
Definition: PasswordPolicyChecks.php:68
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:183
PasswordPolicyChecks\checkPopularPasswordBlacklist
static checkPopularPasswordBlacklist( $policyVal, User $user, $password)
Ensure that password isn't in top X most popular passwords.
Definition: PasswordPolicyChecks.php:132
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:50
$username
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:783
PasswordPolicyChecks
Functions to check passwords against a policy requirement.
Definition: PasswordPolicyChecks.php:29
$wgContLang
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 content language as $wgContLang
Definition: design.txt:56