52 parent::__construct( $params );
53 $this->loginOnly = !empty( $params[
'loginOnly'] );
54 $this->dbProvider = $dbProvider;
67 if ( $expiration ===
null || (
int)$expiration >= $now ) {
72 if ( (
int)$expiration + $grace < $now ) {
89 if ( !$req || $req->username ===
null || $req->password ===
null ) {
93 $username = $this->userNameUtils->getCanonical(
94 $req->username, UserRigorOptions::RIGOR_USABLE );
95 if ( $username ===
false ) {
99 $row = $this->dbProvider->getReplicaDatabase()->newSelectQueryBuilder()
100 ->select( [
'user_id',
'user_password',
'user_password_expires' ] )
102 ->where( [
'user_name' => $username ] )
103 ->caller( __METHOD__ )->fetchRow();
111 $oldRow = clone $row;
114 if ( preg_match(
'/^[0-9a-f]{32}$/', $row->user_password ) ) {
115 $row->user_password =
":B:{$row->user_id}:{$row->user_password}";
119 if ( !$status->isOK() ) {
123 $pwhash = $this->
getPassword( $row->user_password );
124 if ( !$pwhash->verify( $req->password ) ) {
128 $cp1252Password = iconv(
'UTF-8',
'WINDOWS-1252//TRANSLIT', $req->password );
129 if ( $cp1252Password === $req->password || !$pwhash->verify( $cp1252Password ) ) {
142 $dbw = $this->dbProvider->getPrimaryDatabase();
143 $dbw->newUpdateQueryBuilder()
145 ->
set( [
'user_password' => $newHash->toString() ] )
147 'user_id' => $oldRow->user_id,
148 'user_password' => $oldRow->user_password,
150 ->caller( $fname )->execute();
161 $username = $this->userNameUtils->getCanonical(
162 $username, UserRigorOptions::RIGOR_USABLE );
163 if ( $username ===
false ) {
167 $row = $this->dbProvider->getReplicaDatabase()->newSelectQueryBuilder()
168 ->select( [
'user_password' ] )
170 ->where( [
'user_name' => $username ] )
171 ->caller( __METHOD__ )->fetchRow();
178 if ( preg_match(
'/^[0-9a-f]{32}$/', $row->user_password ) ) {
182 return !$this->
getPassword( $row->user_password ) instanceof \InvalidPassword;
186 $username = $this->userNameUtils->getCanonical(
187 $username, UserRigorOptions::RIGOR_USABLE );
188 if ( $username ===
false ) {
194 return (
bool)$db->newSelectQueryBuilder()
195 ->select( [
'user_id' ] )
197 ->where( [
'user_name' => $username ] )
198 ->options( $options )
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();
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();
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.
static getDBOptions( $bitfield)
Get an appropriate DB index, options, and fallback DB index for a query.
static getDBFromIndex(IConnectionProvider $dbProvider, int $index)
Takes $index from ::getDBOptions() and return proper Database object.
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
Add an update to the pending update queue that invokes the specified callback when run.
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()
static newFatal( $message,... $parameters)
Factory function for fatal errors.
static newGood( $value=null)
Factory function for good results.