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
;
25 * This represents the intention to set a temporary password for the user.
29 class TemporaryPasswordAuthenticationRequest
extends AuthenticationRequest
{
30 /** @var string|null Temporary password */
33 /** @var bool Email password to the user. */
34 public $mailpassword = false;
37 * @var bool Do not fail certain operations if the password cannot be mailed, there is a
38 * backchannel present.
40 public $hasBackchannel = false;
42 /** @var string Username or IP address of the caller */
45 public function getFieldInfo() {
49 'label' => wfMessage( 'createaccountmail' ),
50 'help' => wfMessage( 'createaccountmail-help' ),
56 * @param string|null $password
58 public function __construct( $password = null ) {
59 $this->password
= $password;
61 $this->mailpassword
= true;
66 * Return an instance with a new, random password
67 * @return TemporaryPasswordAuthenticationRequest
69 public static function newRandom() {
70 $config = \ConfigFactory
::getDefaultInstance()->makeConfig( 'main' );
72 // get the min password length
73 $minLength = $config->get( 'MinimalPasswordLength' );
74 $policy = $config->get( 'PasswordPolicy' );
75 foreach ( $policy['policies'] as $p ) {
76 if ( isset( $p['MinimalPasswordLength'] ) ) {
77 $minLength = max( $minLength, $p['MinimalPasswordLength'] );
79 if ( isset( $p['MinimalPasswordLengthToLogin'] ) ) {
80 $minLength = max( $minLength, $p['MinimalPasswordLengthToLogin'] );
84 $password = \PasswordFactory
::generateRandomPasswordString( $minLength );
86 return new self( $password );
90 * Return an instance with an invalid password
91 * @return TemporaryPasswordAuthenticationRequest
93 public static function newInvalid() {
94 $request = new self( null );
98 public function describeCredentials() {
100 'provider' => wfMessage( 'authmanager-provider-temporarypassword' ),
101 'account' => new \
RawMessage( '$1', [ $this->username
] ),
102 ] + parent
::describeCredentials();