MediaWiki REL1_35
BotPassword Class Reference

Utility class for bot passwords. More...

Inheritance diagram for BotPassword:
Collaboration diagram for BotPassword:

Public Member Functions

 delete ()
 Delete the BotPassword from the database.
 
 getAppId ()
 Get the app ID.
 
 getGrants ()
 Get the grants.
 
 getRestrictions ()
 Get the restrictions.
 
 getToken ()
 Get the token.
 
 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 ( $username, $password)
 There are two ways to login with a bot password: "username@appId", "password" and "username", "appId@password".
 
static generatePassword ( $config)
 Returns a (raw, unhashed) random password string.
 
static getDB ( $db)
 Get a database connection for the bot passwords database.
 
static getSeparator ()
 Get the separator for combined user name + app ID.
 
static invalidateAllPasswordsForCentralId ( $centralId)
 Invalidate all passwords for a user, by central ID.
 
static invalidateAllPasswordsForUser ( $username)
 Invalidate all passwords for a user, by name.
 
static login ( $username, $password, WebRequest $request)
 Try to log the user in.
 
static newFromCentralId ( $centralId, $appId, $flags=self::READ_NORMAL)
 Load a BotPassword from the database.
 
static newFromUser (User $user, $appId, $flags=self::READ_NORMAL)
 Load a BotPassword from the database.
 
static newUnsaved (array $data, $flags=self::READ_NORMAL)
 Create an unsaved BotPassword.
 
static removeAllPasswordsForCentralId ( $centralId)
 Remove all passwords for a user, by central ID.
 
static removeAllPasswordsForUser ( $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.
 
- Public Attributes inherited from IDBAccessObject
const READ_LOCKING = self::READ_LATEST | 2
 Constants for object loading bitfield flags (higher => higher QoS)
 
const READ_NONE = -1
 

Protected Member Functions

 __construct ( $row, $isSaved, $flags=self::READ_NORMAL)
 
 getPassword ()
 Get the password.
 

Static Private Member Functions

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

Private Attributes

string $appId
 
int $centralId
 
int $flags = self::READ_NORMAL
 
string[] $grants
 
bool $isSaved
 
MWRestrictions $restrictions
 
string $token
 

Detailed Description

Utility class for bot passwords.

Since
1.27

Definition at line 30 of file BotPassword.php.

Constructor & Destructor Documentation

◆ __construct()

BotPassword::__construct (   $row,
  $isSaved,
  $flags = self::READ_NORMAL 
)
protected
Parameters
object$rowbot_passwords database row
bool$isSavedWhether the bot password was read from the database
int$flagsIDBAccessObject read flags

Definition at line 77 of file BotPassword.php.

References 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
array|false

Definition at line 463 of file BotPassword.php.

◆ delete()

BotPassword::delete ( )

Delete the BotPassword from the database.

Returns
bool Success

Definition at line 362 of file BotPassword.php.

References DB_MASTER, getDB(), and isSaved().

◆ generatePassword()

static BotPassword::generatePassword (   $config)
static

Returns a (raw, unhashed) random password string.

Parameters
Config$config
Returns
string

Definition at line 449 of file BotPassword.php.

◆ getAppId()

BotPassword::getAppId ( )

Get the app ID.

Returns
string

Definition at line 216 of file BotPassword.php.

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

◆ 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_MASTER or DB_REPLICA.
Returns
IDatabase

Definition at line 93 of file BotPassword.php.

References $wgBotPasswordsCluster, and $wgBotPasswordsDatabase.

◆ getGrants()

BotPassword::getGrants ( )

Get the grants.

Returns
string[]

Definition at line 240 of file BotPassword.php.

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

◆ getPassword()

BotPassword::getPassword ( )
protected

Get the password.

Returns
Password

Definition at line 257 of file BotPassword.php.

References getDB().

Referenced by isInvalid().

◆ getRestrictions()

BotPassword::getRestrictions ( )

Get the restrictions.

Returns
MWRestrictions

Definition at line 232 of file BotPassword.php.

◆ getSeparator()

static BotPassword::getSeparator ( )
static

Get the separator for combined user name + app ID.

Returns
string

Definition at line 248 of file BotPassword.php.

References $wgUserrightsInterwikiDelimiter.

◆ getToken()

BotPassword::getToken ( )

Get the token.

Returns
string

Definition at line 224 of file BotPassword.php.

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

◆ getUserCentralId()

BotPassword::getUserCentralId ( )

Get the central user ID.

Returns
int

Definition at line 208 of file BotPassword.php.

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

◆ invalidateAllPasswordsForCentralId()

static BotPassword::invalidateAllPasswordsForCentralId (   $centralId)
static

Invalidate all passwords for a user, by central ID.

Parameters
int$centralId
Returns
bool Whether any passwords were invalidated

Definition at line 394 of file BotPassword.php.

References $wgEnableBotPasswords, DB_MASTER, and getDB().

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

◆ isInvalid()

BotPassword::isInvalid ( )

Whether the password is currently invalid.

Since
1.32
Returns
bool

Definition at line 284 of file BotPassword.php.

References getPassword().

◆ isSaved()

BotPassword::isSaved ( )

Indicate whether this is known to be saved.

Returns
bool

Definition at line 200 of file BotPassword.php.

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

References $wgEnableBotPasswords, $wgPasswordAttemptThrottle, WebRequest\getIP(), User\newFromName(), and wfMessage().

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

References Status\getMessage(), and StatusValue\isGood().

◆ 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 $wgEnableBotPasswords, and getDB().

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

◆ newFromUser()

static BotPassword::newFromUser ( User  $user,
  $appId,
  $flags = self::READ_NORMAL 
)
static

Load a BotPassword from the database.

Parameters
User$user
string$appId
int$flagsIDBAccessObject read flags
Returns
BotPassword|null

Definition at line 110 of file BotPassword.php.

◆ 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: (User) User object 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) App ID for the password.
  • restrictions: (MWRestrictions, optional) Restrictions.
  • grants: (string[], optional) Grants.
int$flagsIDBAccessObject read flags
Returns
BotPassword|null

Definition at line 155 of file BotPassword.php.

References MWRestrictions\newDefault().

◆ removeAllPasswordsForCentralId()

static BotPassword::removeAllPasswordsForCentralId (   $centralId)
static

Remove all passwords for a user, by central ID.

Parameters
int$centralId
Returns
bool Whether any passwords were removed

Definition at line 428 of file BotPassword.php.

References $wgEnableBotPasswords, DB_MASTER, and getDB().

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

Referenced by MediaWiki\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 295 of file BotPassword.php.

References $res, DB_MASTER, MWCryptRand\generateHex(), getDB(), isSaved(), MWRestrictions\toJson(), and User\TOKEN_LENGTH.

Member Data Documentation

◆ $appId

string BotPassword::$appId
private

Definition at line 58 of file BotPassword.php.

◆ $centralId

int BotPassword::$centralId
private

Definition at line 55 of file BotPassword.php.

◆ $flags

int BotPassword::$flags = self::READ_NORMAL
private

Definition at line 70 of file BotPassword.php.

◆ $grants

string [] BotPassword::$grants
private

Definition at line 67 of file BotPassword.php.

◆ $isSaved

bool BotPassword::$isSaved
private

Definition at line 52 of file BotPassword.php.

◆ $restrictions

MWRestrictions BotPassword::$restrictions
private

Definition at line 64 of file BotPassword.php.

◆ $token

string BotPassword::$token
private

Definition at line 61 of file BotPassword.php.

◆ APPID_MAXLENGTH

const BotPassword::APPID_MAXLENGTH = 32

Definition at line 32 of file BotPassword.php.

◆ GRANTS_MAXLENGTH

const BotPassword::GRANTS_MAXLENGTH = 65535

Maximum length of the json representation of grants.

Since
1.35.1

Definition at line 49 of file BotPassword.php.

◆ PASSWORD_MINLENGTH

const BotPassword::PASSWORD_MINLENGTH = 32

Minimum length for a bot password.

Definition at line 37 of file BotPassword.php.

◆ RESTRICTIONS_MAXLENGTH

const BotPassword::RESTRICTIONS_MAXLENGTH = 65535

Maximum length of the json representation of restrictions.

Since
1.35.1

Definition at line 43 of file BotPassword.php.


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