MessageCache invalidation improvements
[mediawiki.git] / includes / auth / TemporaryPasswordAuthenticationRequest.php
blobbc7c779d90f1be37e060845e807cf07deb9f70ea
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\MediaWikiServices;
26 /**
27 * This represents the intention to set a temporary password for the user.
28 * @ingroup Auth
29 * @since 1.27
31 class TemporaryPasswordAuthenticationRequest extends AuthenticationRequest {
32 /** @var string|null Temporary password */
33 public $password;
35 /** @var bool Email password to the user. */
36 public $mailpassword = false;
38 /** @var string Username or IP address of the caller */
39 public $caller;
41 public function getFieldInfo() {
42 return [
43 'mailpassword' => [
44 'type' => 'checkbox',
45 'label' => wfMessage( 'createaccountmail' ),
46 'help' => wfMessage( 'createaccountmail-help' ),
51 /**
52 * @param string|null $password
54 public function __construct( $password = null ) {
55 $this->password = $password;
56 if ( $password ) {
57 $this->mailpassword = true;
61 /**
62 * Return an instance with a new, random password
63 * @return TemporaryPasswordAuthenticationRequest
65 public static function newRandom() {
66 $config = MediaWikiServices::getInstance()->getMainConfig();
68 // get the min password length
69 $minLength = $config->get( 'MinimalPasswordLength' );
70 $policy = $config->get( 'PasswordPolicy' );
71 foreach ( $policy['policies'] as $p ) {
72 if ( isset( $p['MinimalPasswordLength'] ) ) {
73 $minLength = max( $minLength, $p['MinimalPasswordLength'] );
75 if ( isset( $p['MinimalPasswordLengthToLogin'] ) ) {
76 $minLength = max( $minLength, $p['MinimalPasswordLengthToLogin'] );
80 $password = \PasswordFactory::generateRandomPasswordString( $minLength );
82 return new self( $password );
85 /**
86 * Return an instance with an invalid password
87 * @return TemporaryPasswordAuthenticationRequest
89 public static function newInvalid() {
90 $request = new self( null );
91 return $request;
94 public function describeCredentials() {
95 return [
96 'provider' => wfMessage( 'authmanager-provider-temporarypassword' ),
97 'account' => new \RawMessage( '$1', [ $this->username ] ),
98 ] + parent::describeCredentials();