| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
namespace MediaWiki\Auth; |
| 23 |
|
| 24 |
use MediaWiki\Language\RawMessage; |
| 25 |
use MediaWiki\MainConfigNames; |
| 26 |
use MediaWiki\MediaWikiServices; |
| 27 |
use MediaWiki\Password\PasswordFactory; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class TemporaryPasswordAuthenticationRequest extends AuthenticationRequest { |
| 36 |
|
| 37 |
public $password; |
| 38 |
|
| 39 |
|
| 40 |
public $mailpassword = false; |
| 41 |
|
| 42 |
|
| 43 |
public $caller; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public function getFieldInfo() { |
| 50 |
return [ |
| 51 |
'mailpassword' => [ |
| 52 |
'type' => 'checkbox', |
| 53 |
'label' => wfMessage( 'createaccountmail' ), |
| 54 |
'help' => wfMessage( 'createaccountmail-help' ), |
| 55 |
], |
| 56 |
]; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public function __construct( $password = null ) { |
| 64 |
$this->password = $password; |
| 65 |
if ( $password ) { |
| 66 |
$this->mailpassword = true; |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public static function newRandom() { |
| 75 |
$config = MediaWikiServices::getInstance()->getMainConfig(); |
| 76 |
|
| 77 |
|
| 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 ); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
$password = PasswordFactory::generateRandomPasswordString( $minLength ); |
| 87 |
|
| 88 |
return new self( $password ); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public static function newInvalid() { |
| 96 |
return new self( null ); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public function describeCredentials() { |
| 104 |
return [ |
| 105 |
'provider' => wfMessage( 'authmanager-provider-temporarypassword' ), |
| 106 |
'account' => new RawMessage( '$1', [ $this->username ] ), |
| 107 |
] + parent::describeCredentials(); |
| 108 |
} |
| 109 |
|
| 110 |
} |