MediaWiki master
MediaWiki\User\BotPassword Class Reference

Utility class for bot passwords. More...

Public Member Functions

 __construct (stdClass $row, private bool $isSaved, private readonly int $flags=IDBAccessObject::READ_NORMAL,)
 delete ()
 Delete the BotPassword from the database.
 getAppId ()
 getGrants ()
 getRestrictions ()
 getToken ()
 getUserCentralId ()
 Get the central user ID.
 isInvalid ()
 Whether the password is currently invalid.
 isSaved ()
 Indicate whether this is known to be saved.
 save ( $operation, ?Password $password=null)
 Save the BotPassword to the database.

Static Public Member Functions

static canonicalizeLoginData (string $username, string $password)
 There are two ways to login with a bot password: "username@appId", "password" and "username", "appId@password".
static generatePassword ()
 Returns a (raw, unhashed) random password string.
static getPrimaryDatabase ()
static getReplicaDatabase ()
static getSeparator ()
 Get the separator for combined username + app ID.
static invalidateAllPasswordsForUser (string $username)
 Invalidate all passwords for a user, by name.
static login (string $username, string $password, WebRequest $request)
 Try to log the user in.
static newFromCentralId ( $centralId, $appId, $flags=IDBAccessObject::READ_NORMAL)
 Load a BotPassword from the database.
static newFromUser (UserIdentity $userIdentity, $appId, $flags=IDBAccessObject::READ_NORMAL)
 Load a BotPassword from the database.
static newUnsaved (array $data, $flags=IDBAccessObject::READ_NORMAL)
 Create an unsaved BotPassword.
static removeAllPasswordsForUser (string $username)
 Remove all passwords for a user, by name.

Public Attributes

const APPID_MAXLENGTH = 32
const GRANTS_MAXLENGTH = 65535
 Maximum length of the json representation of grants.
const PASSWORD_MINLENGTH = 32
 Minimum length for a bot password.
const RESTRICTIONS_MAXLENGTH = 65535
 Maximum length of the json representation of restrictions.

Detailed Description

Utility class for bot passwords.

Since
1.27

Definition at line 34 of file BotPassword.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\User\BotPassword::__construct ( stdClass $row,
private bool $isSaved,
private readonly int $flags = IDBAccessObject::READ_NORMAL )
Access: internal
only public for construction in BotPasswordStore
Parameters
stdClass$rowbot_passwords database row
bool$isSavedWhether the bot password was read from the database
int$flagsIDBAccessObject read flags

Definition at line 70 of file BotPassword.php.

Member Function Documentation

◆ canonicalizeLoginData()

MediaWiki\User\BotPassword::canonicalizeLoginData ( string $username,
string $password )
static

There are two ways to login with a bot password: "username@appId", "password" and "username", "appId@password".

Transform it so it is always in the first form. Returns [bot username, bot password]. If this cannot be a bot password login just return false.

Parameters
string$username
string$password
Returns
string[]|false

Definition at line 299 of file BotPassword.php.

Referenced by MediaWiki\Api\ApiLogin\execute().

◆ delete()

MediaWiki\User\BotPassword::delete ( )

Delete the BotPassword from the database.

Returns
bool Success

Definition at line 250 of file BotPassword.php.

References MediaWiki\MediaWikiServices\getInstance(), and isSaved().

◆ generatePassword()

MediaWiki\User\BotPassword::generatePassword ( )
static

Returns a (raw, unhashed) random password string.

Definition at line 286 of file BotPassword.php.

References PASSWORD_MINLENGTH, and return.

Referenced by CreateBotPassword\execute().

◆ getAppId()

MediaWiki\User\BotPassword::getAppId ( )

◆ getGrants()

MediaWiki\User\BotPassword::getGrants ( )
Returns
string[]

Definition at line 167 of file BotPassword.php.

Referenced by MediaWiki\Session\BotPasswordSessionProvider\newSessionForRequest().

◆ getPrimaryDatabase()

MediaWiki\User\BotPassword::getPrimaryDatabase ( )
static

Definition at line 88 of file BotPassword.php.

References getPrimaryDatabase(), and return.

Referenced by getPrimaryDatabase().

◆ getReplicaDatabase()

MediaWiki\User\BotPassword::getReplicaDatabase ( )
static

Definition at line 82 of file BotPassword.php.

References getReplicaDatabase(), and return.

Referenced by getReplicaDatabase().

◆ getRestrictions()

MediaWiki\User\BotPassword::getRestrictions ( )

◆ getSeparator()

MediaWiki\User\BotPassword::getSeparator ( )
static

Get the separator for combined username + app ID.

Definition at line 174 of file BotPassword.php.

References return.

◆ getToken()

MediaWiki\User\BotPassword::getToken ( )

◆ getUserCentralId()

MediaWiki\User\BotPassword::getUserCentralId ( )

◆ invalidateAllPasswordsForUser()

MediaWiki\User\BotPassword::invalidateAllPasswordsForUser ( string $username)
static

Invalidate all passwords for a user, by name.

Parameters
string$username
Returns
bool Whether any passwords were invalidated

Definition at line 266 of file BotPassword.php.

References return.

Referenced by InvalidateBotPasswords\execute().

◆ isInvalid()

MediaWiki\User\BotPassword::isInvalid ( )

Whether the password is currently invalid.

Since
1.32

Definition at line 208 of file BotPassword.php.

References return.

◆ isSaved()

MediaWiki\User\BotPassword::isSaved ( )

Indicate whether this is known to be saved.

Definition at line 141 of file BotPassword.php.

References isSaved(), and return.

Referenced by delete(), isSaved(), and save().

◆ login()

MediaWiki\User\BotPassword::login ( string $username,
string $password,
WebRequest $request )
static

Try to log the user in.

Parameters
string$usernameCombined username and app ID
string$passwordSupplied password
WebRequest$request
Returns
Status On success, the good status's value is the new Session object

Definition at line 325 of file BotPassword.php.

References $request, MediaWiki\MainConfigNames\EnableBotPasswords, MediaWiki\MediaWikiServices\getInstance(), MediaWiki\User\User\newFromName(), MediaWiki\MainConfigNames\PasswordAttemptThrottle, and wfMessage().

Referenced by MediaWiki\Api\ApiLogin\execute().

◆ newFromCentralId()

MediaWiki\User\BotPassword::newFromCentralId ( $centralId,
$appId,
$flags = IDBAccessObject::READ_NORMAL )
static

Load a BotPassword from the database.

Parameters
int$centralIdfrom CentralIdLookup
string$appId
int$flagsIDBAccessObject read flags
Returns
BotPassword|null

Definition at line 114 of file BotPassword.php.

References MediaWiki\MediaWikiServices\getInstance().

◆ newFromUser()

MediaWiki\User\BotPassword::newFromUser ( UserIdentity $userIdentity,
$appId,
$flags = IDBAccessObject::READ_NORMAL )
static

Load a BotPassword from the database.

Parameters
UserIdentity$userIdentity
string$appId
int$flagsIDBAccessObject read flags
Returns
BotPassword|null

Definition at line 101 of file BotPassword.php.

References MediaWiki\MediaWikiServices\getInstance().

◆ newUnsaved()

MediaWiki\User\BotPassword::newUnsaved ( array $data,
$flags = IDBAccessObject::READ_NORMAL )
static

Create an unsaved BotPassword.

Parameters
array$dataData to use to create the bot password. Keys are:
  • user: (UserIdentity) UserIdentity to create the password for. Overrides username and centralId.
  • username: (string) Username to create the password for. Overrides centralId.
  • centralId: (int) User central ID to create the password for.
  • appId: (string, required) App ID for the password.
  • restrictions: (MWRestrictions, optional) Restrictions.
  • grants: (string[], optional) Grants.
int$flagsIDBAccessObject read flags
Returns
BotPassword|null

Definition at line 132 of file BotPassword.php.

References MediaWiki\MediaWikiServices\getInstance().

Referenced by CreateBotPassword\execute().

◆ removeAllPasswordsForUser()

MediaWiki\User\BotPassword::removeAllPasswordsForUser ( string $username)
static

Remove all passwords for a user, by name.

Parameters
string$username
Returns
bool Whether any passwords were removed

Definition at line 277 of file BotPassword.php.

References return.

◆ save()

MediaWiki\User\BotPassword::save ( $operation,
?Password $password = null )

Save the BotPassword to the database.

Parameters
string$operation'update' or 'insert'
Password | null$passwordPassword to set.
Returns
Status
Exceptions
UnexpectedValueException

Definition at line 219 of file BotPassword.php.

References MediaWiki\MediaWikiServices\getInstance(), and isSaved().

Member Data Documentation

◆ APPID_MAXLENGTH

const MediaWiki\User\BotPassword::APPID_MAXLENGTH = 32

Definition at line 36 of file BotPassword.php.

◆ GRANTS_MAXLENGTH

const MediaWiki\User\BotPassword::GRANTS_MAXLENGTH = 65535

Maximum length of the json representation of grants.

Since
1.36

Definition at line 53 of file BotPassword.php.

◆ PASSWORD_MINLENGTH

const MediaWiki\User\BotPassword::PASSWORD_MINLENGTH = 32

Minimum length for a bot password.

Definition at line 41 of file BotPassword.php.

Referenced by CreateBotPassword\execute(), and generatePassword().

◆ RESTRICTIONS_MAXLENGTH

const MediaWiki\User\BotPassword::RESTRICTIONS_MAXLENGTH = 65535

Maximum length of the json representation of restrictions.

Since
1.36

Definition at line 47 of file BotPassword.php.


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