9use BadMethodCallException;
20use Wikimedia\Timestamp\TimestampFormat as TS;
45 parent::__construct( $params );
46 $this->loginOnly = !empty( $params[
'loginOnly'] );
47 $this->dbProvider = $dbProvider;
60 if ( $expiration ===
null || (
int)$expiration >= $now ) {
65 if ( (
int)$expiration + $grace < $now ) {
68 'msg' => Status::newFatal(
'resetpass-expired' )->getMessage(),
73 'msg' => Status::newFatal(
'resetpass-expired-soft' )->getMessage(),
83 if ( !$req || $req->username ===
null || $req->password ===
null ) {
87 $username = $this->userNameUtils->getCanonical(
88 $req->username, UserRigorOptions::RIGOR_USABLE );
89 if ( $username ===
false ) {
93 $row = $this->dbProvider->getReplicaDatabase()->newSelectQueryBuilder()
94 ->select( [
'user_id',
'user_password',
'user_password_expires' ] )
96 ->where( [
'user_name' => $username ] )
97 ->caller( __METHOD__ )->fetchRow();
105 $oldRow = clone $row;
108 if ( preg_match(
'/^[0-9a-f]{32}$/', $row->user_password ) ) {
109 $row->user_password =
":B:{$row->user_id}:{$row->user_password}";
113 if ( !$status->isOK() ) {
117 $pwhash = $this->
getPassword( $row->user_password );
118 if ( !$pwhash->verify( $req->password ) ) {
122 $cp1252Password = iconv(
'UTF-8',
'WINDOWS-1252//TRANSLIT', $req->password );
123 if ( $cp1252Password === $req->password || !$pwhash->verify( $cp1252Password ) ) {
134 DeferredUpdates::addCallableUpdate(
function ( $fname ) use ( $newHash, $oldRow ) {
135 $dbw = $this->dbProvider->getPrimaryDatabase();
136 $dbw->newUpdateQueryBuilder()
138 ->
set( [
'user_password' => $newHash->toString() ] )
140 'user_id' => $oldRow->user_id,
141 'user_password' => $oldRow->user_password,
156 $username = $this->userNameUtils->getCanonical(
158 UserRigorOptions::RIGOR_USABLE
160 if ( $username ===
false ) {
164 $password = $this->dbProvider->getReplicaDatabase()->newSelectQueryBuilder()
165 ->select( [
'user_password' ] )
167 ->where( [
'user_name' => $username ] )
168 ->caller( __METHOD__ )
170 if ( $password ===
false ) {
176 if ( preg_match(
'/^[0-9a-f]{32}$/', $password ) ) {
184 public function testUserExists( $username, $flags = IDBAccessObject::READ_NORMAL ) {
185 $username = $this->userNameUtils->getCanonical(
187 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 ] )
198 ->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();
284 $ret = StatusValue::newGood();
285 if ( !$this->loginOnly && $req && $req->username !==
null && $req->password !==
null ) {
286 if ( $req->password !== $req->retype ) {
287 $ret->fatal(
'badretype' );
300 throw new BadMethodCallException(
'Shouldn\'t call this when accountCreationType() is NONE' );
304 if ( $req && $req->username !==
null && $req->password !==
null ) {
307 if ( $req->username !== $user->getName() ) {
309 $req->username = $user->getName();
312 $ret->createRequest = $req;
321 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.