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 ] )
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()