MediaWiki master
TemporaryPasswordPrimaryAuthenticationProvider.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Auth;
8
13
28{
29
31 public function testUserExists( $username, $flags = IDBAccessObject::READ_NORMAL ) {
32 $username = $this->userNameUtils->getCanonical( $username, UserRigorOptions::RIGOR_USABLE );
33 if ( $username === false ) {
34 return false;
35 }
36 $db = DBAccessObjectUtils::getDBFromRecency( $this->dbProvider, $flags );
37 return (bool)$db->newSelectQueryBuilder()
38 ->select( [ 'user_id' ] )
39 ->from( 'user' )
40 ->where( [ 'user_name' => $username ] )
41 ->caller( __METHOD__ )->fetchField();
42 }
43
45 protected function getTemporaryPassword( string $username, $flags = IDBAccessObject::READ_NORMAL ): array {
46 $db = DBAccessObjectUtils::getDBFromRecency( $this->dbProvider, $flags );
47 $row = $db->newSelectQueryBuilder()
48 ->select( [ 'user_newpassword', 'user_newpass_time' ] )
49 ->from( 'user' )
50 ->where( [ 'user_name' => $username ] )
51 ->caller( __METHOD__ )->fetchRow();
52
53 if ( !$row ) {
54 return [ null, null ];
55 }
56 return [
57 $this->getPassword( $row->user_newpassword ),
58 $row->user_newpass_time,
59 ];
60 }
61
63 protected function setTemporaryPassword( string $username, Password $tempPassHash, $tempPassTime ): void {
64 $db = $this->dbProvider->getPrimaryDatabase();
65 $db->newUpdateQueryBuilder()
66 ->update( 'user' )
67 ->set( [
68 'user_newpassword' => $tempPassHash->toString(),
69 'user_newpass_time' => $db->timestampOrNull( $tempPassTime ),
70 ] )
71 ->where( [ 'user_name' => $username ] )
72 ->caller( __METHOD__ )->execute();
73 }
74
75}
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.Single-sign-on providers can use this to reserve a username for au...
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.The password may be an Invali...
Represents a password hash for use in authentication.
Definition Password.php:52
toString()
Convert this hash to a string that can be stored in the database.
Definition Password.php:164
Shared interface for rigor levels when dealing with User methods.
Interface for database access objects.