MediaWiki REL1_37
TemporaryPasswordAuthenticationRequest.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Auth;
23
25
34 public $password;
35
37 public $mailpassword = false;
38
40 public $caller;
41
46 public function getFieldInfo() {
47 return [
48 'mailpassword' => [
49 'type' => 'checkbox',
50 'label' => wfMessage( 'createaccountmail' ),
51 'help' => wfMessage( 'createaccountmail-help' ),
52 ],
53 ];
54 }
55
60 public function __construct( $password = null ) {
61 $this->password = $password;
62 if ( $password ) {
63 $this->mailpassword = true;
64 }
65 }
66
71 public static function newRandom() {
72 $config = MediaWikiServices::getInstance()->getMainConfig();
73
74 // get the min password length
75 $minLength = $config->get( 'MinimalPasswordLength' );
76 $policy = $config->get( 'PasswordPolicy' );
77 foreach ( $policy['policies'] as $p ) {
78 foreach ( [ 'MinimalPasswordLength', 'MinimumPasswordLengthToLogin' ] as $check ) {
79 $minLength = max( $minLength, $p[$check]['value'] ?? $p[$check] ?? 0 );
80 }
81 }
82
83 $password = \PasswordFactory::generateRandomPasswordString( $minLength );
84
85 return new self( $password );
86 }
87
92 public static function newInvalid() {
93 $request = new self( null );
94 return $request;
95 }
96
101 public function describeCredentials() {
102 return [
103 'provider' => wfMessage( 'authmanager-provider-temporarypassword' ),
104 'account' => new \RawMessage( '$1', [ $this->username ] ),
105 ] + parent::describeCredentials();
106 }
107
108}
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
This is a value object for authentication requests.
This represents the intention to set a temporary password for the user.
static newRandom()
Return an instance with a new, random password.
describeCredentials()
Describe the credentials represented by this request.This is used on requests returned by Authenticat...
static newInvalid()
Return an instance with an invalid password.
getFieldInfo()
Fetch input field info.The field info is an associative array mapping field names to info arrays....
MediaWikiServices is the service locator for the application scope of MediaWiki.
static getInstance()
Returns the global default instance of the top level service locator.