MediaWiki master
AbstractPbkdf2Password Class Reference

A PBKDF2-hashed password. More...

Inherits ParameterizedPassword.

Inherited by Pbkdf2PasswordUsingHashExtension, and Pbkdf2PasswordUsingOpenSSL.

Collaboration diagram for AbstractPbkdf2Password:

Public Member Functions

 crypt (string $password)
 Hash a password and store the result in this object.
 
- Public Member Functions inherited from ParameterizedPassword
 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 Password
 __construct (PasswordFactory $factory, array $config, string $hash=null)
 Construct the Password object using a string hash.
 
 getType ()
 Get the type name of the password.
 
 verify (string $password)
 Checks whether the given password matches the hash stored in this object.
 

Static Public Member Functions

static newInstance (PasswordFactory $factory, array $config, string $hash=null)
 Create a new AbstractPbkdf2Password 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.
 
 getDigestAlgo (string $algo)
 Get the implementation specific name for a hash algorithm.
 
 pbkdf2 (string $digestAlgo, string $password, string $salt, int $rounds, int $length)
 Call the PBKDF2 implementation, which hashes the password.
 
- Protected Member Functions inherited from ParameterizedPassword
 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 Password
 assertIsSafeSize (string $hash)
 Assert that hash will fit in a tinyblob field.
 
 isSupported ()
 Whether current password type is supported on this system.
 

Static Protected Member Functions

static canUseOpenSSL ()
 Check if OpenSSL can be used for computing PBKDF2 password hashes.
 

Additional Inherited Members

- Protected Attributes inherited from ParameterizedPassword
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 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

A PBKDF2-hashed password.

This is a computationally complex password hash for use in modern applications. The number of rounds can be configured by $wgPasswordConfig['pbkdf2']['cost'].

To support different native implementations of PBKDF2 and the underlying hash algorithms, the following subclasses are available:

Since
1.40

Definition at line 42 of file AbstractPbkdf2Password.php.

Member Function Documentation

◆ canUseOpenSSL()

static AbstractPbkdf2Password::canUseOpenSSL ( )
staticprotected

Check if OpenSSL can be used for computing PBKDF2 password hashes.

Returns
bool

Definition at line 76 of file AbstractPbkdf2Password.php.

◆ crypt()

AbstractPbkdf2Password::crypt ( string $password)

Hash a password and store the result in this object.

The result of the password hash should be put into the internal state of the hash object.

Parameters
string$passwordPassword to hash
Exceptions
PasswordErrorIf an internal error occurs in hashing

Reimplemented from Password.

Definition at line 96 of file AbstractPbkdf2Password.php.

◆ getDefaultParams()

AbstractPbkdf2Password::getDefaultParams ( )
protected

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 from ParameterizedPassword.

Definition at line 84 of file AbstractPbkdf2Password.php.

◆ getDelimiter()

AbstractPbkdf2Password::getDelimiter ( )
protected

Returns the delimiter for the parameters inside the hash.

Returns
string

Reimplemented from ParameterizedPassword.

Definition at line 92 of file AbstractPbkdf2Password.php.

◆ getDigestAlgo()

AbstractPbkdf2Password::getDigestAlgo ( string $algo)
abstractprotected

Get the implementation specific name for a hash algorithm.

Parameters
string$algoAlgorithm specified in the password hash string
Returns
string|null $algo Implementation specific name, or null if unsupported

Reimplemented in Pbkdf2PasswordUsingHashExtension, and Pbkdf2PasswordUsingOpenSSL.

◆ newInstance()

static AbstractPbkdf2Password::newInstance ( PasswordFactory $factory,
array $config,
string $hash = null )
static

Create a new AbstractPbkdf2Password object.

In the default configuration, this is used as a factory function in order to select a PBKDF2 implementation automatically.

Access: internal
See also
Password::__construct
Parameters
PasswordFactory$factoryFactory object that created the password
array$configArray of engine configuration options for hashing
string | null$hashThe raw hash, including the type
Returns
AbstractPbkdf2Password The created object

Definition at line 56 of file AbstractPbkdf2Password.php.

References Password\$hash.

◆ pbkdf2()

AbstractPbkdf2Password::pbkdf2 ( string $digestAlgo,
string $password,
string $salt,
int $rounds,
int $length )
abstractprotected

Call the PBKDF2 implementation, which hashes the password.

Parameters
string$digestAlgoImplementation specific hash algorithm name
string$passwordPassword to hash
string$saltSalt as a binary string
int$roundsNumber of iterations
int$lengthLength of the hash value in bytes
Returns
string Hash value as a binary string
Exceptions
PasswordErrorIf an internal error occurs in hashing

Reimplemented in Pbkdf2PasswordUsingHashExtension, and Pbkdf2PasswordUsingOpenSSL.


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