MediaWiki  master
BotPassword Class Reference

Utility class for bot passwords. More...

Inheritance diagram for BotPassword:
Collaboration diagram for BotPassword:

Public Member Functions

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

Static Public Member Functions

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

Public Attributes

const APPID_MAXLENGTH = 32
 
const GRANTS_MAXLENGTH = 65535
 Maximum length of the json representation of grants. More...
 
const PASSWORD_MINLENGTH = 32
 Minimum length for a bot password. More...
 
const RESTRICTIONS_MAXLENGTH = 65535
 Maximum length of the json representation of restrictions. More...
 
- Public Attributes inherited from IDBAccessObject
const READ_NONE = -1
 Constants for object loading bitfield flags (higher => higher QoS) More...
 

Private Member Functions

 getPassword ()
 

Static Private Member Functions

static loginHook ( $user, $bp, Status $status)
 Call AuthManagerLoginAuthenticateAudit. More...
 

Private Attributes

string $appId
 
int $centralId
 
int $flags
 Defaults to {. More...
 
string[] $grants
 
bool $isSaved
 
MWRestrictions $restrictions
 
string $token
 

Detailed Description

Utility class for bot passwords.

Since
1.27

Definition at line 33 of file BotPassword.php.

Constructor & Destructor Documentation

◆ __construct()

BotPassword::__construct (   $row,
  $isSaved,
  $flags = self::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 82 of file BotPassword.php.

References $flags, $isSaved, FormatJson\decode(), isSaved(), and MWRestrictions\newFromJson().

Member Function Documentation

◆ canonicalizeLoginData()

static BotPassword::canonicalizeLoginData (   $username,
  $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 378 of file BotPassword.php.

References $appId, and getSeparator().

Referenced by ApiLogin\execute().

◆ delete()

BotPassword::delete ( )

Delete the BotPassword from the database.

Returns
bool Success

Definition at line 273 of file BotPassword.php.

References isSaved().

◆ generatePassword()

static BotPassword::generatePassword (   $config)
static

Returns a (raw, unhashed) random password string.

Parameters
Config$config
Returns
string

Definition at line 364 of file BotPassword.php.

References PasswordFactory\generateRandomPasswordString().

Referenced by CreateBotPassword\execute(), and SpecialBotPasswords\save().

◆ getAppId()

◆ getDB()

static BotPassword::getDB (   $db)
static

Get a database connection for the bot passwords database.

Parameters
int$dbIndex of the connection to get, e.g. DB_PRIMARY or DB_REPLICA.
Returns
IDatabase

Definition at line 98 of file BotPassword.php.

Referenced by SpecialBotPasswords\getFormFields(), getPassword(), invalidateAllPasswordsForCentralId(), and removeAllPasswordsForCentralId().

◆ getGrants()

◆ getPassword()

BotPassword::getPassword ( )
private
Returns
Password

Definition at line 204 of file BotPassword.php.

References getDB(), DBAccessObjectUtils\getDBOptions(), and PasswordFactory\newInvalidPassword().

Referenced by isInvalid().

◆ getRestrictions()

◆ getSeparator()

static BotPassword::getSeparator ( )
static

Get the separator for combined user name + app ID.

Returns
string

Definition at line 196 of file BotPassword.php.

References $wgUserrightsInterwikiDelimiter.

Referenced by canonicalizeLoginData(), SpecialBotPasswords\getFormFields(), login(), loginHook(), and SpecialBotPasswords\onSuccess().

◆ getToken()

BotPassword::getToken ( )
Returns
string

Definition at line 174 of file BotPassword.php.

References $token.

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

◆ getUserCentralId()

◆ invalidateAllPasswordsForCentralId()

static BotPassword::invalidateAllPasswordsForCentralId (   $centralId)
static

Invalidate all passwords for a user, by central ID.

Deprecated:
since 1.37
Parameters
int$centralId
Returns
bool Whether any passwords were invalidated

Definition at line 303 of file BotPassword.php.

References $centralId, $wgEnableBotPasswords, DB_PRIMARY, getDB(), PasswordFactory\newInvalidPassword(), and wfDeprecated().

◆ invalidateAllPasswordsForUser()

static BotPassword::invalidateAllPasswordsForUser (   $username)
static

Invalidate all passwords for a user, by name.

Parameters
string$usernameUser name
Returns
bool Whether any passwords were invalidated

Definition at line 289 of file BotPassword.php.

Referenced by InvalidateBotPasswords\execute().

◆ isInvalid()

BotPassword::isInvalid ( )

Whether the password is currently invalid.

Since
1.32
Returns
bool

Definition at line 231 of file BotPassword.php.

References getPassword().

◆ isSaved()

BotPassword::isSaved ( )

Indicate whether this is known to be saved.

Returns
bool

Definition at line 152 of file BotPassword.php.

References $isSaved.

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

◆ login()

static BotPassword::login (   $username,
  $password,
WebRequest  $request 
)
static

Try to log the user in.

Parameters
string$usernameCombined user name 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 404 of file BotPassword.php.

References $appId, $wgEnableBotPasswords, $wgPasswordAttemptThrottle, WebRequest\getIP(), ObjectCache\getLocalClusterInstance(), getSeparator(), loginHook(), StatusValue\newFatal(), User\newFromName(), newFromUser(), StatusValue\newGood(), and wfMessage().

Referenced by ApiLogin\execute().

◆ loginHook()

static BotPassword::loginHook (   $user,
  $bp,
Status  $status 
)
staticprivate

Call AuthManagerLoginAuthenticateAudit.

To facilitate logging all authentications, even ones not via AuthManager, call the AuthManagerLoginAuthenticateAudit hook.

Parameters
User | string$userUser being logged in
BotPassword | null$bpBot sub-account, if it can be identified
Status$statusLogin status
Returns
Status The passed-in status

Definition at line 489 of file BotPassword.php.

References Status\getMessage(), getSeparator(), StatusValue\isGood(), and Hooks\runner().

Referenced by login().

◆ newFromCentralId()

static BotPassword::newFromCentralId (   $centralId,
  $appId,
  $flags = self::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 124 of file BotPassword.php.

References $appId, $centralId, and $flags.

Referenced by SpecialBotPasswords\getFormFields(), SpecialBotPasswords\onSubmit(), and MediaWiki\Session\Session\BotPasswordSessionProvider\refreshSessionInfo().

◆ newFromUser()

static BotPassword::newFromUser ( UserIdentity  $userIdentity,
  $appId,
  $flags = self::READ_NORMAL 
)
static

Load a BotPassword from the database.

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

Definition at line 111 of file BotPassword.php.

References $appId, and $flags.

Referenced by login().

◆ newUnsaved()

static BotPassword::newUnsaved ( array  $data,
  $flags = self::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 142 of file BotPassword.php.

References $flags.

Referenced by CreateBotPassword\execute(), SpecialBotPasswords\getFormFields(), and SpecialBotPasswords\save().

◆ removeAllPasswordsForCentralId()

static BotPassword::removeAllPasswordsForCentralId (   $centralId)
static

Remove all passwords for a user, by central ID.

Deprecated:
since 1.37
Parameters
int$centralId
Returns
bool Whether any passwords were removed

Definition at line 341 of file BotPassword.php.

References $centralId, $wgEnableBotPasswords, DB_PRIMARY, getDB(), and wfDeprecated().

◆ removeAllPasswordsForUser()

static BotPassword::removeAllPasswordsForUser (   $username)
static

Remove all passwords for a user, by name.

Parameters
string$usernameUser name
Returns
bool Whether any passwords were removed

Definition at line 327 of file BotPassword.php.

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

◆ save()

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 242 of file BotPassword.php.

References isSaved(), StatusValue\newGood(), and Status\wrap().

Member Data Documentation

◆ $appId

string BotPassword::$appId
private

Definition at line 61 of file BotPassword.php.

Referenced by canonicalizeLoginData(), getAppId(), login(), newFromCentralId(), and newFromUser().

◆ $centralId

int BotPassword::$centralId
private

◆ $flags

int BotPassword::$flags
private

Defaults to {.

See also
READ_NORMAL}

Definition at line 73 of file BotPassword.php.

Referenced by __construct(), newFromCentralId(), newFromUser(), and newUnsaved().

◆ $grants

string [] BotPassword::$grants
private

Definition at line 70 of file BotPassword.php.

Referenced by getGrants().

◆ $isSaved

bool BotPassword::$isSaved
private

Definition at line 55 of file BotPassword.php.

Referenced by __construct(), and isSaved().

◆ $restrictions

MWRestrictions BotPassword::$restrictions
private

Definition at line 67 of file BotPassword.php.

Referenced by getRestrictions().

◆ $token

string BotPassword::$token
private

Definition at line 64 of file BotPassword.php.

Referenced by getToken().

◆ APPID_MAXLENGTH

const BotPassword::APPID_MAXLENGTH = 32

◆ GRANTS_MAXLENGTH

const BotPassword::GRANTS_MAXLENGTH = 65535

Maximum length of the json representation of grants.

Since
1.36

Definition at line 52 of file BotPassword.php.

Referenced by MediaWiki\User\BotPasswordStore\validateBotPassword().

◆ PASSWORD_MINLENGTH

const BotPassword::PASSWORD_MINLENGTH = 32

Minimum length for a bot password.

Definition at line 40 of file BotPassword.php.

Referenced by CreateBotPassword\execute().

◆ RESTRICTIONS_MAXLENGTH

const BotPassword::RESTRICTIONS_MAXLENGTH = 65535

Maximum length of the json representation of restrictions.

Since
1.36

Definition at line 46 of file BotPassword.php.

Referenced by MediaWiki\User\BotPasswordStore\validateBotPassword().


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