MediaWiki  1.34.0
TemporaryPasswordAuthenticationRequest.php
Go to the documentation of this file.
1 <?php
22 namespace MediaWiki\Auth;
23 
25 
33  public $password;
34 
36  public $mailpassword = false;
37 
39  public $caller;
40 
41  public function getFieldInfo() {
42  return [
43  'mailpassword' => [
44  'type' => 'checkbox',
45  'label' => wfMessage( 'createaccountmail' ),
46  'help' => wfMessage( 'createaccountmail-help' ),
47  ],
48  ];
49  }
50 
54  public function __construct( $password = null ) {
55  $this->password = $password;
56  if ( $password ) {
57  $this->mailpassword = true;
58  }
59  }
60 
65  public static function newRandom() {
66  $config = MediaWikiServices::getInstance()->getMainConfig();
67 
68  // get the min password length
69  $minLength = $config->get( 'MinimalPasswordLength' );
70  $policy = $config->get( 'PasswordPolicy' );
71  foreach ( $policy['policies'] as $p ) {
72  foreach ( [ 'MinimalPasswordLength', 'MinimumPasswordLengthToLogin' ] as $check ) {
73  $minLength = max( $minLength, $p[$check]['value'] ?? $p[$check] ?? 0 );
74  }
75  }
76 
78 
79  return new self( $password );
80  }
81 
86  public static function newInvalid() {
87  $request = new self( null );
88  return $request;
89  }
90 
91  public function describeCredentials() {
92  return [
93  'provider' => wfMessage( 'authmanager-provider-temporarypassword' ),
94  'account' => new \RawMessage( '$1', [ $this->username ] ),
95  ] + parent::describeCredentials();
96  }
97 
98 }
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
MediaWiki\Auth\TemporaryPasswordAuthenticationRequest\__construct
__construct( $password=null)
Definition: TemporaryPasswordAuthenticationRequest.php:54
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1264
PasswordFactory\generateRandomPasswordString
static generateRandomPasswordString( $minLength=10)
Generate a random string suitable for a password.
Definition: PasswordFactory.php:225
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:138
Config\get
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
MediaWiki\Auth\TemporaryPasswordAuthenticationRequest\getFieldInfo
getFieldInfo()
Fetch input field info.
Definition: TemporaryPasswordAuthenticationRequest.php:41
MediaWiki\Auth\TemporaryPasswordAuthenticationRequest\$password
string null $password
Temporary password.
Definition: TemporaryPasswordAuthenticationRequest.php:33
MediaWiki\Auth\TemporaryPasswordAuthenticationRequest\newInvalid
static newInvalid()
Return an instance with an invalid password.
Definition: TemporaryPasswordAuthenticationRequest.php:86
MediaWiki\Auth\TemporaryPasswordAuthenticationRequest\$caller
string $caller
Username or IP address of the caller.
Definition: TemporaryPasswordAuthenticationRequest.php:39
MediaWiki\Auth\TemporaryPasswordAuthenticationRequest\$mailpassword
bool $mailpassword
Email password to the user.
Definition: TemporaryPasswordAuthenticationRequest.php:36
MediaWiki\Auth\TemporaryPasswordAuthenticationRequest\describeCredentials
describeCredentials()
Describe the credentials represented by this request.
Definition: TemporaryPasswordAuthenticationRequest.php:91
MediaWiki\$config
Config $config
Definition: MediaWiki.php:43
MediaWiki\Auth\TemporaryPasswordAuthenticationRequest
This represents the intention to set a temporary password for the user.
Definition: TemporaryPasswordAuthenticationRequest.php:31
MediaWiki\Auth\TemporaryPasswordAuthenticationRequest\newRandom
static newRandom()
Return an instance with a new, random password.
Definition: TemporaryPasswordAuthenticationRequest.php:65
MediaWiki\Auth
Definition: AbstractAuthenticationProvider.php:22
MediaWiki\Auth\AuthenticationRequest
This is a value object for authentication requests.
Definition: AuthenticationRequest.php:37