MediaWiki master
TemporaryPasswordAuthenticationRequest.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Auth;
8
13
23 public $password;
24
26 public $mailpassword = false;
27
29 public $caller;
30
35 public function getFieldInfo() {
36 return [
37 'mailpassword' => [
38 'type' => 'checkbox',
39 'label' => wfMessage( 'createaccountmail' ),
40 'help' => wfMessage( 'createaccountmail-help' ),
41 ],
42 ];
43 }
44
49 public function __construct( $password = null ) {
50 $this->password = $password;
51 if ( $password ) {
52 $this->mailpassword = true;
53 }
54 }
55
60 public static function newRandom() {
61 $config = MediaWikiServices::getInstance()->getMainConfig();
62
63 // get the min password length
64 $minLength = 0;
65 $policy = $config->get( MainConfigNames::PasswordPolicy );
66 foreach ( $policy['policies'] as $p ) {
67 foreach ( [ 'MinimalPasswordLength', 'MinimumPasswordLengthToLogin' ] as $check ) {
68 $minLength = max( $minLength, $p[$check]['value'] ?? $p[$check] ?? 0 );
69 }
70 }
71
72 $password = PasswordFactory::generateRandomPasswordString( $minLength );
73
74 return new self( $password );
75 }
76
81 public static function newInvalid() {
82 return new self( null );
83 }
84
89 public function describeCredentials() {
90 return [
91 'provider' => wfMessage( 'authmanager-provider-temporarypassword' ),
92 'account' => new RawMessage( '$1', [ $this->username ] ),
93 ] + parent::describeCredentials();
94 }
95
96}
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.