MediaWiki master
MediaWiki\Password\ParameterizedPassword Class Reference

Helper class for password hash types that have a delimited set of parameters inside the hash. More...

Inherits MediaWiki\Password\Password.

Inherited by MediaWiki\Password\AbstractPbkdf2Password, MediaWiki\Password\BcryptPassword, MediaWiki\Password\EncryptedPassword, MediaWiki\Password\LayeredParameterizedPassword, MediaWiki\Password\MWOldPassword, and MediaWiki\Password\MWSaltedPassword.

Collaboration diagram for MediaWiki\Password\ParameterizedPassword:

Public Member Functions

 needsUpdate ()
 Determine if the hash needs to be updated.
 
 toString ()
 Convert this hash to a string that can be stored in the database.
 
- Public Member Functions inherited from MediaWiki\Password\Password
 __construct (PasswordFactory $factory, array $config, ?string $hash=null)
 Construct the Password object using a string hash.
 
 crypt (string $password)
 Hash a password and store the result in this object.
 
 getType ()
 Get the type name of the password.
 
 verify (string $password)
 Checks whether the given password matches the hash stored in this object.
 

Protected Member Functions

 getDefaultParams ()
 Return an ordered array of default parameters for this password hash.
 
 getDelimiter ()
 Returns the delimiter for the parameters inside the hash.
 
 parseHash (?string $hash)
 Perform any parsing necessary on the hash to see if the hash is valid and/or to perform logic for seeing if the hash needs updating.
Parameters
string | null$hashThe hash, with the :<TYPE>: prefix stripped
Exceptions
PasswordErrorIf there is an error in parsing the hash

 
- Protected Member Functions inherited from MediaWiki\Password\Password
 assertIsSafeSize (string $hash)
 Assert that hash will fit in a tinyblob field.
 
 isSupported ()
 Whether current password type is supported on this system.
 

Protected Attributes

string[] $args = []
 Extra arguments that were found in the hash.
 
array $params = []
 Named parameters that have default values for this password type.
 
- Protected Attributes inherited from MediaWiki\Password\Password
array $config
 Array of configuration variables injected from the constructor.
 
PasswordFactory $factory
 Factory that created the object.
 
string null $hash
 String representation of the hash without the type.
 

Detailed Description

Helper class for password hash types that have a delimited set of parameters inside the hash.

All passwords are in the form of :<TYPE>:... as explained in the main Password class. This class is for hashes in the form of :<TYPE>:<PARAM1>:<PARAM2>:... where <PARAM1>, <PARAM2>, etc. are parameters that determine how the password was hashed. Of course, the internal delimiter (which is : by convention and default), can be changed by overriding the ParameterizedPassword::getDelimiter() function.

This class requires overriding an additional function: ParameterizedPassword::getDefaultParams(). See the function description for more details on the implementation.

Since
1.24

Definition at line 42 of file ParameterizedPassword.php.

Member Function Documentation

◆ getDefaultParams()

MediaWiki\Password\ParameterizedPassword::getDefaultParams ( )
abstractprotected

Return an ordered array of default parameters for this password hash.

The keys should be the parameter names and the values should be the default values. Additionally, the order of the array should be the order in which they appear in the hash.

When parsing a password hash, the constructor will split the hash based on the delimiter, and consume as many parts as it can, matching each to a parameter in this list. Once all the parameters have been filled, all remaining parts will be considered extra arguments, except, of course, for the very last part, which is the hash itself.

Returns
array

Reimplemented in MediaWiki\Password\AbstractPbkdf2Password, MediaWiki\Password\BcryptPassword, MediaWiki\Password\EncryptedPassword, MediaWiki\Password\LayeredParameterizedPassword, MediaWiki\Password\MWOldPassword, and MediaWiki\Password\MWSaltedPassword.

Referenced by MediaWiki\Password\ParameterizedPassword\parseHash().

◆ getDelimiter()

MediaWiki\Password\ParameterizedPassword::getDelimiter ( )
abstractprotected

◆ needsUpdate()

MediaWiki\Password\ParameterizedPassword::needsUpdate ( )

Determine if the hash needs to be updated.

Returns
bool True if needs update, false otherwise

Reimplemented from MediaWiki\Password\Password.

Definition at line 88 of file ParameterizedPassword.php.

◆ parseHash()

MediaWiki\Password\ParameterizedPassword::parseHash ( ?string $hash)
protected

Perform any parsing necessary on the hash to see if the hash is valid and/or to perform logic for seeing if the hash needs updating.

Parameters
string | null$hashThe hash, with the :<TYPE>: prefix stripped
Exceptions
PasswordErrorIf there is an error in parsing the hash

Reimplemented from MediaWiki\Password\Password.

Reimplemented in MediaWiki\Password\BcryptPassword.

Definition at line 59 of file ParameterizedPassword.php.

References MediaWiki\Password\ParameterizedPassword\getDefaultParams().

◆ toString()

MediaWiki\Password\ParameterizedPassword::toString ( )

Convert this hash to a string that can be stored in the database.

The resulting string should be considered the serialized representation of this hash, i.e., if the return value were recycled back into PasswordFactory::newFromCiphertext, the returned object would be equivalent to this; also, if two objects return the same value from this function, they are considered equivalent.

Returns
string
Exceptions
PasswordErrorif password cannot be serialized to fit a tinyblob.

Reimplemented from MediaWiki\Password\Password.

Definition at line 92 of file ParameterizedPassword.php.

Member Data Documentation

◆ $args

string [] MediaWiki\Password\ParameterizedPassword::$args = []
protected

Extra arguments that were found in the hash.

This may or may not make the hash invalid.

Definition at line 54 of file ParameterizedPassword.php.

◆ $params

array MediaWiki\Password\ParameterizedPassword::$params = []
protected

Named parameters that have default values for this password type.

Definition at line 47 of file ParameterizedPassword.php.


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