Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / auth / TemporaryPasswordAuthenticationRequest.php
blob612153179ee042be21f8a2dc7eaf54541363aca8
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
19 * @ingroup Auth
22 namespace MediaWiki\Auth;
24 use MediaWiki\Language\RawMessage;
25 use MediaWiki\MainConfigNames;
26 use MediaWiki\MediaWikiServices;
27 use MediaWiki\Password\PasswordFactory;
29 /**
30 * This represents the intention to set a temporary password for the user.
31 * @stable to extend
32 * @ingroup Auth
33 * @since 1.27
35 class TemporaryPasswordAuthenticationRequest extends AuthenticationRequest {
36 /** @var string|null Temporary password */
37 public $password;
39 /** @var bool Email password to the user. */
40 public $mailpassword = false;
42 /** @var string Username or IP address of the caller */
43 public $caller;
45 /**
46 * @inheritDoc
47 * @stable to override
49 public function getFieldInfo() {
50 return [
51 'mailpassword' => [
52 'type' => 'checkbox',
53 'label' => wfMessage( 'createaccountmail' ),
54 'help' => wfMessage( 'createaccountmail-help' ),
59 /**
60 * @stable to call
61 * @param string|null $password
63 public function __construct( $password = null ) {
64 $this->password = $password;
65 if ( $password ) {
66 $this->mailpassword = true;
70 /**
71 * Return an instance with a new, random password
72 * @return TemporaryPasswordAuthenticationRequest
74 public static function newRandom() {
75 $config = MediaWikiServices::getInstance()->getMainConfig();
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 );
86 $password = PasswordFactory::generateRandomPasswordString( $minLength );
88 return new self( $password );
91 /**
92 * Return an instance with an invalid password
93 * @return TemporaryPasswordAuthenticationRequest
95 public static function newInvalid() {
96 return new self( null );
99 /**
100 * @inheritDoc
101 * @stable to override
103 public function describeCredentials() {
104 return [
105 'provider' => wfMessage( 'authmanager-provider-temporarypassword' ),
106 'account' => new RawMessage( '$1', [ $this->username ] ),
107 ] + parent::describeCredentials();