MediaWiki
REL1_24
|
Represents a password hash for use in authentication. More...
Public Member Functions | |
__construct (PasswordFactory $factory, array $config, $hash=null) | |
Construct the Password object using a string hash. | |
crypt ($password) | |
Hash a password and store the result in this object. | |
equals ($other) | |
Compare one Password object to this object. | |
getType () | |
Get the type name of the password. | |
needsUpdate () | |
Determine if the hash needs to be updated. | |
toString () | |
Convert this hash to a string that can be stored in the database. | |
Protected Member Functions | |
parseHash ($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. | |
Protected Attributes | |
array | $config |
Array of configuration variables injected from the constructor. | |
PasswordFactory | $factory |
Factory that created the object. | |
string | $hash |
String representation of the hash without the type. |
Represents a password hash for use in authentication.
Note: All password types are transparently prefixed with :<TYPE>:, where <TYPE> is the registered type of the hash. This prefix is stripped in the constructor and is added back in the toString() function.
When inheriting this class, there are a couple of expectations to be fulfilled: * If Password::toString() is called on an object, and the result is passed back in to PasswordFactory::newFromCiphertext(), the result will be identical to the original. * The string representations of two Password objects are equal only if the original plaintext passwords match. In other words, if the toString() result of two objects match, the passwords are the same, and the user will be logged in. Since the string representation of a hash includes its type name (
The abstract functions that must be overridden are: * Password::crypt(), which takes a plaintext password and hashes it into a string hash suitable for being passed to the constructor of that class, and then stores that hash (and whatever other data) into the internal state of the object. The functions that can optionally be overridden are: * Password::parseHash(), which can be useful to override if you need to extract values from or otherwise parse a password hash when it's passed to the constructor. * Password::needsUpdate(), which can be useful if a specific password hash has different logic for when the hash needs to be updated. * Password::toString(), which can be useful if the hash was changed in the constructor and needs to be re-assembled before being returned as a string. This function is expected to add the type back on to the hash, so make sure to do that if you override the function. * Password::equals() - This function compares two Password objects to see if they are equal. The default is to just do a timing-safe string comparison on the $this->hash values.
After creating a new password hash type, it can be registered using the static Password::register() method. The default type is set using the Password::setDefaultType() type. Types must be registered before they can be set as the default.
Definition at line 66 of file Password.php.
Password::__construct | ( | PasswordFactory $ | factory, |
array $ | config, | ||
$ | hash = null |
||
) | [final] |
Construct the Password object using a string hash.
It is strongly recommended not to call this function directly unless you have a reason to. Use the PasswordFactory class instead.
MWException | If $config does not contain required parameters |
PasswordFactory | $factory | Factory object that created the password |
array | $config | Array of engine configuration options for hashing |
string | null | $hash | The raw hash, including the type |
Definition at line 93 of file Password.php.
Password::crypt | ( | $ | password | ) | [abstract] |
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.
string | $password | Password to hash |
PasswordError | If an internal error occurs in hashing |
Reimplemented in LayeredParameterizedPassword, BcryptPassword, Pbkdf2Password, EncryptedPassword, MWSaltedPassword, MWOldPassword, and InvalidPassword.
Referenced by LayeredParameterizedPassword\partialCrypt().
Password::equals | ( | $ | other | ) |
Compare one Password object to this object.
By default, do a timing-safe string comparison on the result of Password::toString() for each object. This can be overridden to do custom comparison, but it is not recommended unless necessary.
Password | string | $other | The other password |
Reimplemented in InvalidPassword.
Definition at line 146 of file Password.php.
Password::getType | ( | ) | [final] |
Get the type name of the password.
Definition at line 114 of file Password.php.
Determine if the hash needs to be updated.
Reimplemented in ParameterizedPassword, and InvalidPassword.
Definition at line 133 of file Password.php.
Password::parseHash | ( | $ | 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.
string | $hash | The hash, with the :<TYPE>: prefix stripped |
PasswordError | If there is an error in parsing the hash |
Reimplemented in ParameterizedPassword, and BcryptPassword.
Definition at line 125 of file Password.php.
Convert this hash to a string that can be stored in the database.
The resulting string should be considered the seralized 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.
Reimplemented in ParameterizedPassword, and InvalidPassword.
Definition at line 169 of file Password.php.
array Password::$config [protected] |
Array of configuration variables injected from the constructor.
Definition at line 79 of file Password.php.
PasswordFactory Password::$factory [protected] |
Factory that created the object.
Definition at line 69 of file Password.php.
string Password::$hash [protected] |
String representation of the hash without the type.
Definition at line 74 of file Password.php.
Referenced by Pbkdf2Password\crypt(), BcryptPassword\crypt(), and BcryptPassword\parseHash().