MediaWiki master
TemporaryPasswordPrimaryAuthenticationProvider.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Auth;
23
28
42{
43
44 public function testUserExists( $username, $flags = IDBAccessObject::READ_NORMAL ) {
45 $username = $this->userNameUtils->getCanonical( $username, UserRigorOptions::RIGOR_USABLE );
46 if ( $username === false ) {
47 return false;
48 }
49 $db = DBAccessObjectUtils::getDBFromRecency( $this->dbProvider, $flags );
50 return (bool)$db->newSelectQueryBuilder()
51 ->select( [ 'user_id' ] )
52 ->from( 'user' )
53 ->where( [ 'user_name' => $username ] )
54 ->caller( __METHOD__ )->fetchField();
55 }
56
57 protected function getTemporaryPassword( string $username, $flags = IDBAccessObject::READ_NORMAL ): array {
58 $db = DBAccessObjectUtils::getDBFromRecency( $this->dbProvider, $flags );
59 $row = $db->newSelectQueryBuilder()
60 ->select( [ 'user_newpassword', 'user_newpass_time' ] )
61 ->from( 'user' )
62 ->where( [ 'user_name' => $username ] )
63 ->caller( __METHOD__ )->fetchRow();
64
65 if ( !$row ) {
66 return [ null, null ];
67 }
68 return [
69 $this->getPassword( $row->user_newpassword ),
70 $row->user_newpass_time,
71 ];
72 }
73
74 protected function setTemporaryPassword( string $username, Password $tempPassHash, $tempPassTime ): void {
75 $db = $this->dbProvider->getPrimaryDatabase();
76 $db->newUpdateQueryBuilder()
77 ->update( 'user' )
78 ->set( [
79 'user_newpassword' => $tempPassHash->toString(),
80 'user_newpass_time' => $db->timestampOrNull( $tempPassTime ),
81 ] )
82 ->where( [ 'user_name' => $username ] )
83 ->caller( __METHOD__ )->execute();
84 }
85
86}
A primary authentication provider that uses the temporary password field in the 'user' table.
testUserExists( $username, $flags=IDBAccessObject::READ_NORMAL)
Test whether the named user exists.
setTemporaryPassword(string $username, Password $tempPassHash, $tempPassTime)
Set a temporary password and the time when it was generated.
getTemporaryPassword(string $username, $flags=IDBAccessObject::READ_NORMAL)
Return a tuple of temporary password and the time when it was generated.
Represents a password hash for use in authentication.
Definition Password.php:66
toString()
Convert this hash to a string that can be stored in the database.
Definition Password.php:178
Shared interface for rigor levels when dealing with User methods.
Interface for database access objects.