55 $this->loginOnly = !empty(
$params[
'loginOnly'] );
56 $this->dbProvider = $dbProvider;
69 if ( $expiration ===
null || (
int)$expiration >= $now ) {
74 if ( (
int)$expiration + $grace < $now ) {
77 'msg' => \MediaWiki\Status\Status::newFatal(
'resetpass-expired' )->getMessage(),
82 'msg' => \MediaWiki\Status\Status::newFatal(
'resetpass-expired-soft' )->getMessage(),
91 if ( !$req || $req->username ===
null || $req->password ===
null ) {
95 $username = $this->userNameUtils->getCanonical(
96 $req->username, UserRigorOptions::RIGOR_USABLE );
97 if ( $username ===
false ) {
101 $row = $this->dbProvider->getReplicaDatabase()->newSelectQueryBuilder()
102 ->select( [
'user_id',
'user_password',
'user_password_expires' ] )
104 ->where( [
'user_name' => $username ] )
105 ->caller( __METHOD__ )->fetchRow();
113 $oldRow = clone $row;
116 if ( preg_match(
'/^[0-9a-f]{32}$/', $row->user_password ) ) {
117 $row->user_password =
":B:{$row->user_id}:{$row->user_password}";
121 if ( !$status->isOK() ) {
125 $pwhash = $this->
getPassword( $row->user_password );
126 if ( !$pwhash->verify( $req->password ) ) {
130 $cp1252Password = iconv(
'UTF-8',
'WINDOWS-1252//TRANSLIT', $req->password );
131 if ( $cp1252Password === $req->password || !$pwhash->verify( $cp1252Password ) ) {
142 DeferredUpdates::addCallableUpdate(
function ( $fname ) use ( $newHash, $oldRow ) {
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,
163 $username = $this->userNameUtils->getCanonical(
164 $username, UserRigorOptions::RIGOR_USABLE );
165 if ( $username ===
false ) {
169 $row = $this->dbProvider->getReplicaDatabase()->newSelectQueryBuilder()
170 ->select( [
'user_password' ] )
172 ->where( [
'user_name' => $username ] )
173 ->caller( __METHOD__ )->fetchRow();
180 if ( preg_match(
'/^[0-9a-f]{32}$/', $row->user_password ) ) {
187 public function testUserExists( $username, $flags = IDBAccessObject::READ_NORMAL ) {
188 $username = $this->userNameUtils->getCanonical(
189 $username, UserRigorOptions::RIGOR_USABLE );
190 if ( $username ===
false ) {
194 $db = \DBAccessObjectUtils::getDBFromRecency( $this->dbProvider, $flags );
195 return (
bool)$db->newSelectQueryBuilder()
196 ->select( [
'user_id' ] )
198 ->where( [
'user_name' => $username ] )
200 ->caller( __METHOD__ )->fetchField();
208 if ( $this->loginOnly ) {
209 return \StatusValue::newGood(
'ignored' );
212 if ( get_class( $req ) === PasswordAuthenticationRequest::class ) {
214 return \StatusValue::newGood();
217 $username = $this->userNameUtils->getCanonical( $req->username,
218 UserRigorOptions::RIGOR_USABLE );
219 if ( $username !==
false ) {
220 $row = $this->dbProvider->getPrimaryDatabase()->newSelectQueryBuilder()
221 ->select( [
'user_id' ] )
223 ->where( [
'user_name' => $username ] )
224 ->caller( __METHOD__ )->fetchRow();
226 $sv = \StatusValue::newGood();
227 if ( $req->password !==
null ) {
228 if ( $req->password !== $req->retype ) {
229 $sv->fatal(
'badretype' );
239 return \StatusValue::newGood(
'ignored' );
243 $username = $req->username !==
null ?
244 $this->userNameUtils->getCanonical( $req->username, UserRigorOptions::RIGOR_USABLE )
246 if ( $username ===
false ) {
252 if ( get_class( $req ) === PasswordAuthenticationRequest::class ) {
253 if ( $this->loginOnly ) {
263 $dbw = $this->dbProvider->getPrimaryDatabase();
264 $dbw->newUpdateQueryBuilder()
267 'user_password' => $pwhash->toString(),
269 'user_password_expires' => $dbw->timestampOrNull( $expiry ),
271 ->where( [
'user_name' => $username ] )
272 ->caller( __METHOD__ )->execute();
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.
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.