24use BadMethodCallException;
58 parent::__construct( $params );
59 $this->loginOnly = !empty( $params[
'loginOnly'] );
60 $this->dbProvider = $dbProvider;
73 if ( $expiration ===
null || (
int)$expiration >= $now ) {
78 if ( (
int)$expiration + $grace < $now ) {
81 'msg' => Status::newFatal(
'resetpass-expired' )->getMessage(),
86 'msg' => Status::newFatal(
'resetpass-expired-soft' )->getMessage(),
95 if ( !$req || $req->username ===
null || $req->password ===
null ) {
99 $username = $this->userNameUtils->getCanonical(
100 $req->username, UserRigorOptions::RIGOR_USABLE );
101 if ( $username ===
false ) {
105 $row = $this->dbProvider->getReplicaDatabase()->newSelectQueryBuilder()
106 ->select( [
'user_id',
'user_password',
'user_password_expires' ] )
108 ->where( [
'user_name' => $username ] )
109 ->caller( __METHOD__ )->fetchRow();
117 $oldRow = clone $row;
120 if ( preg_match(
'/^[0-9a-f]{32}$/', $row->user_password ) ) {
121 $row->user_password =
":B:{$row->user_id}:{$row->user_password}";
125 if ( !$status->isOK() ) {
129 $pwhash = $this->
getPassword( $row->user_password );
130 if ( !$pwhash->verify( $req->password ) ) {
134 $cp1252Password = iconv(
'UTF-8',
'WINDOWS-1252//TRANSLIT', $req->password );
135 if ( $cp1252Password === $req->password || !$pwhash->verify( $cp1252Password ) ) {
146 DeferredUpdates::addCallableUpdate(
function ( $fname ) use ( $newHash, $oldRow ) {
147 $dbw = $this->dbProvider->getPrimaryDatabase();
148 $dbw->newUpdateQueryBuilder()
150 ->
set( [
'user_password' => $newHash->toString() ] )
152 'user_id' => $oldRow->user_id,
153 'user_password' => $oldRow->user_password,
167 $username = $this->userNameUtils->getCanonical(
169 UserRigorOptions::RIGOR_USABLE
171 if ( $username ===
false ) {
175 $row = $this->dbProvider->getReplicaDatabase()->newSelectQueryBuilder()
176 ->select( [
'user_password' ] )
178 ->where( [
'user_name' => $username ] )
179 ->caller( __METHOD__ )->fetchRow();
186 if ( preg_match(
'/^[0-9a-f]{32}$/', $row->user_password ) ) {
193 public function testUserExists( $username, $flags = IDBAccessObject::READ_NORMAL ) {
194 $username = $this->userNameUtils->getCanonical(
196 UserRigorOptions::RIGOR_USABLE
198 if ( $username ===
false ) {
202 $db = DBAccessObjectUtils::getDBFromRecency( $this->dbProvider, $flags );
203 return (
bool)$db->newSelectQueryBuilder()
204 ->select( [
'user_id' ] )
206 ->where( [
'user_name' => $username ] )
207 ->caller( __METHOD__ )->fetchField();
215 if ( $this->loginOnly ) {
216 return StatusValue::newGood(
'ignored' );
219 if ( get_class( $req ) === PasswordAuthenticationRequest::class ) {
221 return StatusValue::newGood();
224 $username = $this->userNameUtils->getCanonical( $req->username,
225 UserRigorOptions::RIGOR_USABLE );
226 if ( $username !==
false ) {
227 $row = $this->dbProvider->getPrimaryDatabase()->newSelectQueryBuilder()
228 ->select( [
'user_id' ] )
230 ->where( [
'user_name' => $username ] )
231 ->caller( __METHOD__ )->fetchRow();
233 $sv = StatusValue::newGood();
234 if ( $req->password !==
null ) {
235 if ( $req->password !== $req->retype ) {
236 $sv->fatal(
'badretype' );
246 return StatusValue::newGood(
'ignored' );
250 $username = $req->username !==
null
251 ? $this->userNameUtils->getCanonical( $req->username, UserRigorOptions::RIGOR_USABLE )
253 if ( $username ===
false ) {
259 if ( get_class( $req ) === PasswordAuthenticationRequest::class ) {
260 if ( $this->loginOnly ) {
270 $dbw = $this->dbProvider->getPrimaryDatabase();
271 $dbw->newUpdateQueryBuilder()
274 'user_password' => $pwhash->toString(),
276 'user_password_expires' => $dbw->timestampOrNull( $expiry ),
278 ->where( [
'user_name' => $username ] )
279 ->caller( __METHOD__ )->execute();
290 $ret = StatusValue::newGood();
291 if ( !$this->loginOnly && $req && $req->username !==
null && $req->password !==
null ) {
292 if ( $req->password !== $req->retype ) {
293 $ret->fatal(
'badretype' );
305 throw new BadMethodCallException(
'Shouldn\'t call this when accountCreationType() is NONE' );
309 if ( $req && $req->username !==
null && $req->password !==
null ) {
312 if ( $req->username !== $user->getName() ) {
314 $req->username = $user->getName();
317 $ret->createRequest = $req;
325 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.
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()
Generic operation result class Has warning/error list, boolean status and arbitrary value.