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
22 namespace MediaWiki\Auth
;
24 use MediaWiki\Language\RawMessage
;
25 use MediaWiki\MainConfigNames
;
26 use MediaWiki\MediaWikiServices
;
27 use MediaWiki\Password\PasswordFactory
;
30 * This represents the intention to set a temporary password for the user.
35 class TemporaryPasswordAuthenticationRequest
extends AuthenticationRequest
{
36 /** @var string|null Temporary password */
39 /** @var bool Email password to the user. */
40 public $mailpassword = false;
42 /** @var string Username or IP address of the caller */
49 public function getFieldInfo() {
53 'label' => wfMessage( 'createaccountmail' ),
54 'help' => wfMessage( 'createaccountmail-help' ),
61 * @param string|null $password
63 public function __construct( $password = null ) {
64 $this->password
= $password;
66 $this->mailpassword
= true;
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
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 );
92 * Return an instance with an invalid password
93 * @return TemporaryPasswordAuthenticationRequest
95 public static function newInvalid() {
96 return new self( null );
101 * @stable to override
103 public function describeCredentials() {
105 'provider' => wfMessage( 'authmanager-provider-temporarypassword' ),
106 'account' => new RawMessage( '$1', [ $this->username
] ),
107 ] + parent
::describeCredentials();