MediaWiki  1.34.0
MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider Class Reference

A primary authentication provider that uses the temporary password field in the 'user' table. More...

Inheritance diagram for MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider:
Collaboration diagram for MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider:

Public Member Functions

 __construct ( $params=[])
 
 accountCreationType ()
 Fetch the account-creation type. More...
 
 beginPrimaryAccountCreation ( $user, $creator, array $reqs)
 Start an account creation flow. More...
 
 beginPrimaryAuthentication (array $reqs)
 Start an authentication flow. More...
 
 finishAccountCreation ( $user, $creator, AuthenticationResponse $res)
 Post-creation callback. More...
 
 getAuthenticationRequests ( $action, array $options)
 Return the applicable list of AuthenticationRequests.Possible values for $action depend on whether the implementing class is also a PreAuthenticationProvider, PrimaryAuthenticationProvider, or SecondaryAuthenticationProvider.

  • ACTION_LOGIN: Valid for passing to beginAuthentication. Called on all providers.
  • ACTION_CREATE: Valid for passing to beginAccountCreation. Called on all providers.
  • ACTION_LINK: Valid for passing to beginAccountLink. Called on linking primary providers only.
  • ACTION_CHANGE: Valid for passing to AuthManager::changeAuthenticationData to change credentials. Called on primary and secondary providers.
  • ACTION_REMOVE: Valid for passing to AuthManager::changeAuthenticationData to remove credentials. Must work without additional user input (i.e. without calling loadFromSubmission). Called on primary and secondary providers.
See also
AuthManager::getAuthenticationRequests()
Parameters
string$action
array$optionsOptions are:
  • username: User name related to the action, or null/unset if anon.
    • ACTION_LOGIN: The currently logged-in user, if any.
    • ACTION_CREATE: The account creator, if non-anonymous.
    • ACTION_LINK: The local user being linked to.
    • ACTION_CHANGE: The user having data changed.
    • ACTION_REMOVE: The user having data removed. If you leave the username property of the returned requests empty, this will automatically be copied there (except for ACTION_CREATE where it wouldn't really make sense).
Returns
AuthenticationRequest[]
Of the requests returned by this method, exactly one should have AuthenticationRequest::$required set to REQUIRED.Of the requests returned by this method, exactly one should have AuthenticationRequest::$required set to REQUIRED. More...
 
 providerAllowsAuthenticationDataChange (AuthenticationRequest $req, $checkData=true)
 Validate a change of authentication data (e.g. More...
 
 providerChangeAuthenticationData (AuthenticationRequest $req)
 Change or remove authentication data (e.g. More...
 
 setConfig (\Config $config)
 
 testForAccountCreation ( $user, $creator, array $reqs)
 Determine whether an account creation may begin. More...
 
 testUserCanAuthenticate ( $username)
 Test whether the named user can authenticate with this provider. More...
 
 testUserExists ( $username, $flags=User::READ_NORMAL)
 Test whether the named user exists. More...
 
- Public Member Functions inherited from MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider
 __construct (array $params=[])
 
- Public Member Functions inherited from MediaWiki\Auth\AbstractPrimaryAuthenticationProvider
 autoCreatedAccount ( $user, $source)
 Post-auto-creation callback. More...
 
 beginPrimaryAccountLink ( $user, array $reqs)
 Start linking an account to an existing user. More...
 
 continuePrimaryAccountCreation ( $user, $creator, array $reqs)
 Continue an account creation flow. More...
 
 continuePrimaryAccountLink ( $user, array $reqs)
 Continue linking an account to an existing user. More...
 
 continuePrimaryAuthentication (array $reqs)
 Continue an authentication flow. More...
 
 postAccountCreation ( $user, $creator, AuthenticationResponse $response)
 Post-creation callback. More...
 
 postAccountLink ( $user, AuthenticationResponse $response)
 Post-link callback. More...
 
 postAuthentication ( $user, AuthenticationResponse $response)
 Post-login callback. More...
 
 providerAllowsPropertyChange ( $property)
 Determine whether a property can change. More...
 
 providerNormalizeUsername ( $username)
 Normalize the username for authentication.Any two inputs that would result in the same user being authenticated should return the same string here, while inputs that would result in different users should return different strings.If possible, the best thing to do here is to return the canonicalized name of the local user account that would be used. If not, return something that would be invalid as a local username (e.g. wrap an email address in "<>", or append "#servicename" to the username passed to a third-party service).If the provider doesn't use a username at all in its AuthenticationRequests, return null. If the name is syntactically invalid, it's probably best to return null.
Parameters
string$username
Returns
string|null
More...
 
 providerRevokeAccessForUser ( $username)
 Revoke the user's credentials.This may cause the user to no longer exist for the provider, or the user may continue to exist in a "disabled" state.The intention is that the named account will never again be usable for normal login (i.e. there is no way to undo the revocation of access).
Parameters
string$username
More...
 
 testUserForCreation ( $user, $autocreate, array $options=[])
 Determine whether an account may be created. More...
 
- Public Member Functions inherited from MediaWiki\Auth\AbstractAuthenticationProvider
 getUniqueId ()
 Return a unique identifier for this instance.This must be the same across requests. If multiple instances return the same ID, exceptions will be thrown from AuthManager.
Returns
string
More...
 
 setConfig (Config $config)
 Set configuration. More...
 
 setLogger (LoggerInterface $logger)
 
 setManager (AuthManager $manager)
 Set AuthManager. More...
 

Protected Member Functions

 getPasswordResetData ( $username, $data)
 Get password reset data, if any. More...
 
 isTimestampValid ( $timestamp)
 Check that a temporary password is still valid (hasn't expired). More...
 
 sendNewAccountEmail (User $user, User $creatingUser, $password)
 Send an email about the new account creation and the temporary password. More...
 
 sendPasswordResetEmail (TemporaryPasswordAuthenticationRequest $req)
 
- Protected Member Functions inherited from MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider
 checkPasswordValidity ( $username, $password)
 Check that the password is valid. More...
 
 failResponse (PasswordAuthenticationRequest $req)
 Return the appropriate response for failure. More...
 
 getNewPasswordExpiry ( $username)
 Get expiration date for a new password, if any. More...
 
 getPassword ( $hash)
 Get a Password object from the hash. More...
 
 getPasswordFactory ()
 Get the PasswordFactory. More...
 
 setPasswordResetFlag ( $username, Status $status, $data=null)
 Check if the password should be reset. More...
 

Protected Attributes

bool $emailEnabled = null
 
int $newPasswordExpiry = null
 
int $passwordReminderResendTime = null
 
- Protected Attributes inherited from MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider
bool $authoritative
 Whether this provider should ABSTAIN (false) or FAIL (true) on password failure. More...
 
- Protected Attributes inherited from MediaWiki\Auth\AbstractAuthenticationProvider
Config $config
 
LoggerInterface $logger
 
AuthManager $manager
 

Additional Inherited Members

- Public Attributes inherited from MediaWiki\Auth\PrimaryAuthenticationProvider
const TYPE_CREATE = 'create'
 Provider can create accounts. More...
 
const TYPE_LINK = 'link'
 Provider can link to existing accounts elsewhere. More...
 
const TYPE_NONE = 'none'
 Provider cannot create or link to accounts. More...
 

Detailed Description

A primary authentication provider that uses the temporary password field in the 'user' table.

A successful login will force a password reset.

Note
For proper operation, this should generally come before any other password-based authentication providers.
Since
1.27

Definition at line 37 of file TemporaryPasswordPrimaryAuthenticationProvider.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::__construct (   $params = [])
Parameters
array$params
  • emailEnabled: (bool) must be true for the option to email passwords to be present
  • newPasswordExpiry: (int) expiraton time of temporary passwords, in seconds
  • passwordReminderResendTime: (int) cooldown period in hours until a password reminder can be sent to the same user again,

Definition at line 56 of file TemporaryPasswordPrimaryAuthenticationProvider.php.

Member Function Documentation

◆ accountCreationType()

MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::accountCreationType ( )

Fetch the account-creation type.

Returns
string One of the TYPE_* constants

Implements MediaWiki\Auth\PrimaryAuthenticationProvider.

Definition at line 327 of file TemporaryPasswordPrimaryAuthenticationProvider.php.

References MediaWiki\Auth\PrimaryAuthenticationProvider\TYPE_CREATE.

◆ beginPrimaryAccountCreation()

MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::beginPrimaryAccountCreation (   $user,
  $creator,
array  $reqs 
)

Start an account creation flow.

Parameters
User$userUser being created (not added to the database yet). This may become a "UserValue" in the future, or User may be refactored into such.
User$creatorUser doing the creation. This may become a "UserValue" in the future, or User may be refactored into such.
AuthenticationRequest[]$reqs
Returns
AuthenticationResponse Expected responses:
  • PASS: The user may be created. Secondary providers will now run.
  • FAIL: The user may not be created. Fail the creation process.
  • ABSTAIN: These $reqs are not handled. Some other primary provider may handle it.
  • UI: The $reqs are accepted, no other primary provider will run. Additional AuthenticationRequests are needed to complete the process.
  • REDIRECT: The $reqs are accepted, no other primary provider will run. Redirection to a third party is needed to complete the process.

Implements MediaWiki\Auth\PrimaryAuthenticationProvider.

Definition at line 354 of file TemporaryPasswordPrimaryAuthenticationProvider.php.

References MediaWiki\Auth\AuthenticationRequest\getRequestByClass(), MediaWiki\Auth\AuthenticationResponse\newAbstain(), and MediaWiki\Auth\AuthenticationResponse\newPass().

◆ beginPrimaryAuthentication()

MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::beginPrimaryAuthentication ( array  $reqs)

Start an authentication flow.

Parameters
AuthenticationRequest[]$reqs
Returns
AuthenticationResponse Expected responses:
  • PASS: The user is authenticated. Secondary providers will now run.
  • FAIL: The user is not authenticated. Fail the authentication process.
  • ABSTAIN: These $reqs are not handled. Some other primary provider may handle it.
  • UI: The $reqs are accepted, no other primary provider will run. Additional AuthenticationRequests are needed to complete the process.
  • REDIRECT: The $reqs are accepted, no other primary provider will run. Redirection to a third party is needed to complete the process.

Implements MediaWiki\Auth\PrimaryAuthenticationProvider.

Definition at line 118 of file TemporaryPasswordPrimaryAuthenticationProvider.php.

References $dbr, $status, MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider\checkPasswordValidity(), DB_REPLICA, MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider\failResponse(), User\getCanonicalName(), MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider\getPassword(), MediaWiki\Auth\AuthenticationRequest\getRequestByClass(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider\isTimestampValid(), MediaWiki\Auth\AuthenticationResponse\newAbstain(), MediaWiki\Auth\AuthenticationResponse\newFail(), MediaWiki\Auth\AuthenticationResponse\newPass(), MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider\setPasswordResetFlag(), and wfGetDB().

◆ finishAccountCreation()

MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::finishAccountCreation (   $user,
  $creator,
AuthenticationResponse  $response 
)

Post-creation callback.

Called after the user is added to the database, before secondary authentication providers are run. Only called if this provider was the one that issued a PASS.

Parameters
User$userUser being created (has been added to the database now). This may become a "UserValue" in the future, or User may be refactored into such.
User$creatorUser doing the creation. This may become a "UserValue" in the future, or User may be refactored into such.
AuthenticationResponse$responsePASS response returned earlier
Returns
string|null 'newusers' log subtype to use for logging the account creation. If null, either 'create' or 'create2' will be used depending on $creator.

Reimplemented from MediaWiki\Auth\AbstractPrimaryAuthenticationProvider.

Definition at line 378 of file TemporaryPasswordPrimaryAuthenticationProvider.php.

References $res, DB_MASTER, MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider\providerChangeAuthenticationData(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider\sendNewAccountEmail(), and wfGetDB().

◆ getAuthenticationRequests()

MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::getAuthenticationRequests (   $action,
array  $options 
)

Return the applicable list of AuthenticationRequests.Possible values for $action depend on whether the implementing class is also a PreAuthenticationProvider, PrimaryAuthenticationProvider, or SecondaryAuthenticationProvider.

  • ACTION_LOGIN: Valid for passing to beginAuthentication. Called on all providers.
  • ACTION_CREATE: Valid for passing to beginAccountCreation. Called on all providers.
  • ACTION_LINK: Valid for passing to beginAccountLink. Called on linking primary providers only.
  • ACTION_CHANGE: Valid for passing to AuthManager::changeAuthenticationData to change credentials. Called on primary and secondary providers.
  • ACTION_REMOVE: Valid for passing to AuthManager::changeAuthenticationData to remove credentials. Must work without additional user input (i.e. without calling loadFromSubmission). Called on primary and secondary providers.
See also
AuthManager::getAuthenticationRequests()
Parameters
string$action
array$optionsOptions are:
  • username: User name related to the action, or null/unset if anon.
    • ACTION_LOGIN: The currently logged-in user, if any.
    • ACTION_CREATE: The account creator, if non-anonymous.
    • ACTION_LINK: The local user being linked to.
    • ACTION_CHANGE: The user having data changed.
    • ACTION_REMOVE: The user having data removed. If you leave the username property of the returned requests empty, this will automatically be copied there (except for ACTION_CREATE where it wouldn't really make sense).
Returns
AuthenticationRequest[]
Of the requests returned by this method, exactly one should have AuthenticationRequest::$required set to REQUIRED.Of the requests returned by this method, exactly one should have AuthenticationRequest::$required set to REQUIRED.

Of the requests returned by this method, exactly one should have AuthenticationRequest::$required set to REQUIRED.

Reimplemented from MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider.

Definition at line 92 of file TemporaryPasswordPrimaryAuthenticationProvider.php.

References MediaWiki\$action, MediaWiki\Auth\AuthManager\ACTION_CHANGE, MediaWiki\Auth\AuthManager\ACTION_CREATE, MediaWiki\Auth\AuthManager\ACTION_LOGIN, MediaWiki\Auth\AuthManager\ACTION_REMOVE, and MediaWiki\Auth\TemporaryPasswordAuthenticationRequest\newRandom().

◆ getPasswordResetData()

MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::getPasswordResetData (   $username,
  $data 
)
protected

Get password reset data, if any.

Parameters
string$username
mixed$data
Returns
object|null { 'hard' => bool, 'msg' => Message }

Reimplemented from MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider.

Definition at line 84 of file TemporaryPasswordPrimaryAuthenticationProvider.php.

References wfMessage().

◆ isTimestampValid()

MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::isTimestampValid (   $timestamp)
protected

◆ providerAllowsAuthenticationDataChange()

MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::providerAllowsAuthenticationDataChange ( AuthenticationRequest  $req,
  $checkData = true 
)

Validate a change of authentication data (e.g.

passwords)

Return StatusValue::newGood( 'ignored' ) if you don't support this AuthenticationRequest type.

Parameters
AuthenticationRequest$req
bool$checkDataIf false, $req hasn't been loaded from the submission so checks on user-submitted fields should be skipped. $req->username is considered user-submitted for this purpose, even if it cannot be changed via $req->loadFromSubmission.
Returns
StatusValue

Implements MediaWiki\Auth\PrimaryAuthenticationProvider.

Definition at line 216 of file TemporaryPasswordPrimaryAuthenticationProvider.php.

References MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider\checkPasswordValidity(), DB_MASTER, User\getCanonicalName(), IP\isValid(), User\newFromName(), StatusValue\newGood(), wfGetDB(), and wfTimestamp().

◆ providerChangeAuthenticationData()

MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::providerChangeAuthenticationData ( AuthenticationRequest  $req)

Change or remove authentication data (e.g.

passwords)

If $req was returned for AuthManager::ACTION_CHANGE, the corresponding credentials should result in a successful login in the future.

If $req was returned for AuthManager::ACTION_REMOVE, the corresponding credentials should no longer result in a successful login.

It can be assumed that providerAllowsAuthenticationDataChange with $checkData === true was called before this, and passed. This method should never fail (other than throwing an exception).

Parameters
AuthenticationRequest$req

Implements MediaWiki\Auth\PrimaryAuthenticationProvider.

Definition at line 284 of file TemporaryPasswordPrimaryAuthenticationProvider.php.

References MediaWiki\Auth\AuthManager\ACTION_REMOVE, DB_MASTER, User\getCanonicalName(), MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider\getPasswordFactory(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider\sendPasswordResetEmail(), and wfGetDB().

Referenced by MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider\finishAccountCreation().

◆ sendNewAccountEmail()

MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::sendNewAccountEmail ( User  $user,
User  $creatingUser,
  $password 
)
protected

Send an email about the new account creation and the temporary password.

Parameters
User$userThe new user account
User$creatingUserThe user who created the account (can be anonymous)
string$passwordThe temporary password
Returns
\Status

Definition at line 423 of file TemporaryPasswordPrimaryAuthenticationProvider.php.

References $status, User\getName(), User\getOption(), User\getRequest(), Title\newMainPage(), Hooks\run(), User\sendMail(), and wfMessage().

Referenced by MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider\finishAccountCreation().

◆ sendPasswordResetEmail()

MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::sendPasswordResetEmail ( TemporaryPasswordAuthenticationRequest  $req)
protected

◆ setConfig()

MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::setConfig ( \Config  $config)

◆ testForAccountCreation()

MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::testForAccountCreation (   $user,
  $creator,
array  $reqs 
)

Determine whether an account creation may begin.

Called from AuthManager::beginAccountCreation()

Note
No need to test if the account exists, AuthManager checks that
Parameters
User$userUser being created (not added to the database yet). This may become a "UserValue" in the future, or User may be refactored into such.
User$creatorUser doing the creation. This may become a "UserValue" in the future, or User may be refactored into such.
AuthenticationRequest[]$reqs
Returns
StatusValue

Reimplemented from MediaWiki\Auth\AbstractPrimaryAuthenticationProvider.

Definition at line 331 of file TemporaryPasswordPrimaryAuthenticationProvider.php.

References MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider\checkPasswordValidity(), MediaWiki\Auth\AuthenticationRequest\getRequestByClass(), StatusValue\newFatal(), and StatusValue\newGood().

◆ testUserCanAuthenticate()

MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::testUserCanAuthenticate (   $username)

Test whether the named user can authenticate with this provider.

Should return true if the provider has any data for this user which can be used to authenticate it, even if the user is temporarily prevented from authentication somehow.

Parameters
string$usernameMediaWiki username
Returns
bool

Reimplemented from MediaWiki\Auth\AbstractPrimaryAuthenticationProvider.

Definition at line 172 of file TemporaryPasswordPrimaryAuthenticationProvider.php.

References $dbr, DB_REPLICA, User\getCanonicalName(), MediaWiki\Auth\AbstractPasswordPrimaryAuthenticationProvider\getPassword(), MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider\isTimestampValid(), and wfGetDB().

◆ testUserExists()

MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::testUserExists (   $username,
  $flags = User::READ_NORMAL 
)

Test whether the named user exists.

Single-sign-on providers can use this to reserve a username for autocreation.

Parameters
string$usernameMediaWiki username
int$flagsBitfield of User:READ_* constants
Returns
bool

Implements MediaWiki\Auth\PrimaryAuthenticationProvider.

Definition at line 200 of file TemporaryPasswordPrimaryAuthenticationProvider.php.

References User\getCanonicalName(), DBAccessObjectUtils\getDBOptions(), and wfGetDB().

Member Data Documentation

◆ $emailEnabled

bool MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::$emailEnabled = null
protected

◆ $newPasswordExpiry

int MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::$newPasswordExpiry = null
protected

◆ $passwordReminderResendTime

int MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::$passwordReminderResendTime = null
protected

The documentation for this class was generated from the following file: