45 parent::__construct( $params );
46 $this->loginOnly = !empty( $params[
'loginOnly'] );
59 if ( $expiration ===
null || $expiration >= $now ) {
63 $grace = $this->config->get(
'PasswordExpireGrace' );
64 if ( $expiration + $grace < $now ) {
67 'msg' => \Status::newFatal(
'resetpass-expired' )->getMessage(),
72 'msg' => \Status::newFatal(
'resetpass-expired-soft' )->getMessage(),
85 if ( $req->username ===
null || $req->password ===
null ) {
90 if ( $username ===
false ) {
95 'user_id',
'user_password',
'user_password_expires',
99 $row =
$dbr->selectRow(
102 [
'user_name' => $username ],
112 $oldRow = clone $row;
115 if ( preg_match(
'/^[0-9a-f]{32}$/', $row->user_password ) ) {
116 $row->user_password =
":B:{$row->user_id}:{$row->user_password}";
120 if ( !$status->isOK() ) {
125 $pwhash = $this->
getPassword( $row->user_password );
126 if ( !$pwhash->verify( $req->password ) ) {
127 if ( $this->config->get(
'LegacyEncoding' ) ) {
130 $cp1252Password = iconv(
'UTF-8',
'WINDOWS-1252//TRANSLIT', $req->password );
131 if ( $cp1252Password === $req->password || !$pwhash->verify( $cp1252Password ) ) {
143 \DeferredUpdates::addCallableUpdate(
function () use ( $newHash, $oldRow, $fname ) {
147 [
'user_password' => $newHash->toString() ],
149 'user_id' => $oldRow->user_id,
150 'user_password' => $oldRow->user_password
165 if ( $username ===
false ) {
170 $row =
$dbr->selectRow(
173 [
'user_name' => $username ],
182 if ( preg_match(
'/^[0-9a-f]{32}$/', $row->user_password ) ) {
186 return !$this->
getPassword( $row->user_password ) instanceof \InvalidPassword;
191 if ( $username ===
false ) {
195 list( $db, $options ) = \DBAccessObjectUtils::getDBOptions( $flags );
196 return (
bool)
wfGetDB( $db )->selectField(
199 [
'user_name' => $username ],
210 if ( $this->loginOnly ) {
211 return \StatusValue::newGood(
'ignored' );
214 if ( get_class( $req ) === PasswordAuthenticationRequest::class ) {
216 return \StatusValue::newGood();
220 if ( $username !==
false ) {
224 [
'user_name' => $username ],
228 $sv = \StatusValue::newGood();
229 if ( $req->password !==
null ) {
230 if ( $req->password !== $req->retype ) {
231 $sv->fatal(
'badretype' );
241 return \StatusValue::newGood(
'ignored' );
246 if ( $username ===
false ) {
252 if ( get_class( $req ) === PasswordAuthenticationRequest::class ) {
253 if ( $this->loginOnly ) {
267 'user_password' => $pwhash->toString(),
268 'user_password_expires' => $dbw->timestampOrNull( $expiry ),
270 [
'user_name' => $username ],
283 $ret = \StatusValue::newGood();
284 if ( !$this->loginOnly && $req && $req->username !==
null && $req->password !==
null ) {
285 if ( $req->password !== $req->retype ) {
286 $ret->fatal(
'badretype' );
298 throw new \BadMethodCallException(
'Shouldn\'t call this when accountCreationType() is NONE' );
302 if ( $req && $req->username !==
null && $req->password !==
null ) {
305 if ( $req->username !== $user->getName() ) {
307 $req->username = $user->getName();
310 $ret->createRequest = $req;
318 throw new \BadMethodCallException(
'Shouldn\'t call this when accountCreationType() is NONE' );
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static getCanonicalName( $name, $validate='valid')
Given unvalidated user input, return a canonical username, or false if the username is invalid.