51 parent::__construct( $params );
52 $this->loginOnly = !empty( $params[
'loginOnly'] );
66 if ( $expiration ===
null || (
int)$expiration >= $now ) {
70 $grace = $this->config->get(
'PasswordExpireGrace' );
71 if ( (
int)$expiration + $grace < $now ) {
74 'msg' => \Status::newFatal(
'resetpass-expired' )->getMessage(),
79 'msg' => \Status::newFatal(
'resetpass-expired-soft' )->getMessage(),
92 if ( $req->username ===
null || $req->password ===
null ) {
96 $username = $this->userNameUtils->getCanonical( $req->username, UserNameUtils::RIGOR_USABLE );
97 if ( $username ===
false ) {
102 'user_id',
'user_password',
'user_password_expires',
106 $row =
$dbr->selectRow(
109 [
'user_name' => $username ],
119 $oldRow = clone $row;
122 if ( preg_match(
'/^[0-9a-f]{32}$/', $row->user_password ) ) {
123 $row->user_password =
":B:{$row->user_id}:{$row->user_password}";
127 if ( !$status->isOK() ) {
132 $pwhash = $this->
getPassword( $row->user_password );
133 if ( !$pwhash->verify( $req->password ) ) {
134 if ( $this->config->get(
'LegacyEncoding' ) ) {
137 $cp1252Password = iconv(
'UTF-8',
'WINDOWS-1252//TRANSLIT', $req->password );
138 if ( $cp1252Password === $req->password || !$pwhash->verify( $cp1252Password ) ) {
150 \DeferredUpdates::addCallableUpdate(
function () use ( $newHash, $oldRow, $fname ) {
151 $dbw = $this->loadBalancer->getConnectionRef(
DB_PRIMARY );
154 [
'user_password' => $newHash->toString() ],
156 'user_id' => $oldRow->user_id,
157 'user_password' => $oldRow->user_password
171 $username = $this->userNameUtils->getCanonical( $username, UserNameUtils::RIGOR_USABLE );
172 if ( $username ===
false ) {
177 $row =
$dbr->selectRow(
180 [
'user_name' => $username ],
189 if ( preg_match(
'/^[0-9a-f]{32}$/', $row->user_password ) ) {
193 return !$this->
getPassword( $row->user_password ) instanceof \InvalidPassword;
197 $username = $this->userNameUtils->getCanonical( $username, UserNameUtils::RIGOR_USABLE );
198 if ( $username ===
false ) {
202 list( $db, $options ) = \DBAccessObjectUtils::getDBOptions( $flags );
203 return (
bool)$this->loadBalancer->getConnectionRef( $db )->selectField(
206 [
'user_name' => $username ],
217 if ( $this->loginOnly ) {
218 return \StatusValue::newGood(
'ignored' );
221 if ( get_class( $req ) === PasswordAuthenticationRequest::class ) {
223 return \StatusValue::newGood();
226 $username = $this->userNameUtils->getCanonical( $req->username, UserNameUtils::RIGOR_USABLE );
227 if ( $username !==
false ) {
228 $row = $this->loadBalancer->getConnectionRef(
DB_PRIMARY )->selectRow(
231 [
'user_name' => $username ],
235 $sv = \StatusValue::newGood();
236 if ( $req->password !==
null ) {
237 if ( $req->password !== $req->retype ) {
238 $sv->fatal(
'badretype' );
248 return \StatusValue::newGood(
'ignored' );
252 $username = $req->username !==
null ?
253 $this->userNameUtils->getCanonical( $req->username, UserNameUtils::RIGOR_USABLE ) :
false;
254 if ( $username ===
false ) {
260 if ( get_class( $req ) === PasswordAuthenticationRequest::class ) {
261 if ( $this->loginOnly ) {
271 $dbw = $this->loadBalancer->getConnectionRef(
DB_PRIMARY );
275 'user_password' => $pwhash->toString(),
276 'user_password_expires' => $dbw->timestampOrNull( $expiry ),
278 [
'user_name' => $username ],
291 $ret = \StatusValue::newGood();
292 if ( !$this->loginOnly && $req && $req->username !==
null && $req->password !==
null ) {
293 if ( $req->password !== $req->retype ) {
294 $ret->fatal(
'badretype' );
306 throw new \BadMethodCallException(
'Shouldn\'t call this when accountCreationType() is NONE' );
310 if ( $req && $req->username !==
null && $req->password !==
null ) {
313 if ( $req->username !== $user->getName() ) {
315 $req->username = $user->getName();
318 $ret->createRequest = $req;
326 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.
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,...