54 $this->loginOnly = !empty(
$params[
'loginOnly'] );
55 $this->dbProvider = $dbProvider;
68 if ( $expiration ===
null || (
int)$expiration >= $now ) {
73 if ( (
int)$expiration + $grace < $now ) {
76 'msg' => \MediaWiki\Status\Status::newFatal(
'resetpass-expired' )->getMessage(),
81 'msg' => \MediaWiki\Status\Status::newFatal(
'resetpass-expired-soft' )->getMessage(),
90 if ( !$req || $req->username ===
null || $req->password ===
null ) {
94 $username = $this->userNameUtils->getCanonical(
95 $req->username, UserRigorOptions::RIGOR_USABLE );
96 if ( $username ===
false ) {
100 $row = $this->dbProvider->getReplicaDatabase()->newSelectQueryBuilder()
101 ->select( [
'user_id',
'user_password',
'user_password_expires' ] )
103 ->where( [
'user_name' => $username ] )
104 ->caller( __METHOD__ )->fetchRow();
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() ) {
124 $pwhash = $this->
getPassword( $row->user_password );
125 if ( !$pwhash->verify( $req->password ) ) {
129 $cp1252Password = iconv(
'UTF-8',
'WINDOWS-1252//TRANSLIT', $req->password );
130 if ( $cp1252Password === $req->password || !$pwhash->verify( $cp1252Password ) ) {
142 DeferredUpdates::addCallableUpdate(
function () use ( $newHash, $oldRow, $fname ) {
143 $dbw = $this->dbProvider->getPrimaryDatabase();
144 $dbw->newUpdateQueryBuilder()
146 ->
set( [
'user_password' => $newHash->toString() ] )
148 'user_id' => $oldRow->user_id,
149 'user_password' => $oldRow->user_password,
151 ->caller( $fname )->execute();
162 $username = $this->userNameUtils->getCanonical(
163 $username, UserRigorOptions::RIGOR_USABLE );
164 if ( $username ===
false ) {
168 $row = $this->dbProvider->getReplicaDatabase()->newSelectQueryBuilder()
169 ->select( [
'user_password' ] )
171 ->where( [
'user_name' => $username ] )
172 ->caller( __METHOD__ )->fetchRow();
179 if ( preg_match(
'/^[0-9a-f]{32}$/', $row->user_password ) ) {
183 return !$this->
getPassword( $row->user_password ) instanceof \InvalidPassword;
186 public function testUserExists( $username, $flags = IDBAccessObject::READ_NORMAL ) {
187 $username = $this->userNameUtils->getCanonical(
188 $username, UserRigorOptions::RIGOR_USABLE );
189 if ( $username ===
false ) {
193 $db = \DBAccessObjectUtils::getDBFromRecency( $this->dbProvider, $flags );
194 return (
bool)$db->newSelectQueryBuilder()
195 ->select( [
'user_id' ] )
197 ->where( [
'user_name' => $username ] )
199 ->caller( __METHOD__ )->fetchField();
207 if ( $this->loginOnly ) {
208 return \StatusValue::newGood(
'ignored' );
211 if ( get_class( $req ) === PasswordAuthenticationRequest::class ) {
213 return \StatusValue::newGood();
216 $username = $this->userNameUtils->getCanonical( $req->username,
217 UserRigorOptions::RIGOR_USABLE );
218 if ( $username !==
false ) {
219 $row = $this->dbProvider->getPrimaryDatabase()->newSelectQueryBuilder()
220 ->select( [
'user_id' ] )
222 ->where( [
'user_name' => $username ] )
223 ->caller( __METHOD__ )->fetchRow();
225 $sv = \StatusValue::newGood();
226 if ( $req->password !==
null ) {
227 if ( $req->password !== $req->retype ) {
228 $sv->fatal(
'badretype' );
238 return \StatusValue::newGood(
'ignored' );
242 $username = $req->username !==
null ?
243 $this->userNameUtils->getCanonical( $req->username, UserRigorOptions::RIGOR_USABLE )
245 if ( $username ===
false ) {
251 if ( get_class( $req ) === PasswordAuthenticationRequest::class ) {
252 if ( $this->loginOnly ) {
262 $dbw = $this->dbProvider->getPrimaryDatabase();
263 $dbw->newUpdateQueryBuilder()
266 'user_password' => $pwhash->toString(),
268 'user_password_expires' => $dbw->timestampOrNull( $expiry ),
270 ->where( [
'user_name' => $username ] )
271 ->caller( __METHOD__ )->execute();
282 $ret = \StatusValue::newGood();
283 if ( !$this->loginOnly && $req && $req->username !==
null && $req->password !==
null ) {
284 if ( $req->password !== $req->retype ) {
285 $ret->fatal(
'badretype' );
297 throw new \BadMethodCallException(
'Shouldn\'t call this when accountCreationType() is NONE' );
301 if ( $req && $req->username !==
null && $req->password !==
null ) {
304 if ( $req->username !== $user->getName() ) {
306 $req->username = $user->getName();
309 $ret->createRequest = $req;
317 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.
array $params
The job parameters.
A class containing constants representing the names of configuration variables.
const LegacyEncoding
Name constant for the LegacyEncoding setting, for use with Config::get()
const PasswordExpireGrace
Name constant for the PasswordExpireGrace setting, for use with Config::get()
Interface for database access objects.