MediaWiki master
TemporaryPasswordAuthenticationRequest.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Auth;
23
28
37 public $password;
38
40 public $mailpassword = false;
41
43 public $caller;
44
49 public function getFieldInfo() {
50 return [
51 'mailpassword' => [
52 'type' => 'checkbox',
53 'label' => wfMessage( 'createaccountmail' ),
54 'help' => wfMessage( 'createaccountmail-help' ),
55 ],
56 ];
57 }
58
63 public function __construct( $password = null ) {
64 $this->password = $password;
65 if ( $password ) {
66 $this->mailpassword = true;
67 }
68 }
69
74 public static function newRandom() {
75 $config = MediaWikiServices::getInstance()->getMainConfig();
76
77 // get the min password length
78 $minLength = 0;
79 $policy = $config->get( MainConfigNames::PasswordPolicy );
80 foreach ( $policy['policies'] as $p ) {
81 foreach ( [ 'MinimalPasswordLength', 'MinimumPasswordLengthToLogin' ] as $check ) {
82 $minLength = max( $minLength, $p[$check]['value'] ?? $p[$check] ?? 0 );
83 }
84 }
85
86 $password = PasswordFactory::generateRandomPasswordString( $minLength );
87
88 return new self( $password );
89 }
90
95 public static function newInvalid() {
96 $request = new self( null );
97 return $request;
98 }
99
104 public function describeCredentials() {
105 return [
106 'provider' => wfMessage( 'authmanager-provider-temporarypassword' ),
107 'account' => new RawMessage( '$1', [ $this->username ] ),
108 ] + parent::describeCredentials();
109 }
110
111}
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.This will be used in the AuthManager APIs and web UIs to define API input para...
Variant of the Message class.
A class containing constants representing the names of configuration variables.
const PasswordPolicy
Name constant for the PasswordPolicy setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Factory class for creating and checking Password objects.