23use Wikimedia\Assert\Assert;
98 throw new Exception(
'PHP support not found for ' . get_class( $this ) );
100 if ( !isset( $config[
'type'] ) ) {
101 throw new Exception(
'Password configuration must contain a type name.' );
103 $this->config = $config;
104 $this->factory = $factory;
106 if (
$hash !==
null && strlen(
$hash ) >= 3 ) {
121 return $this->config[
'type'];
166 if ( is_string( $other ) ) {
167 return $this->
verify( $other );
170 return hash_equals( $this->
toString(), $other->toString() );
180 Assert::parameterType(
'string', $password,
'$password' );
185 $obj->crypt( $password );
187 return hash_equals( $this->
toString(), $obj->toString() );
203 $result =
':' . $this->config[
'type'] .
':' . $this->hash;
219 if ( strlen(
$hash ) > self::MAX_HASH_SIZE ) {
233 abstract public function crypt( $password );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Show an error when any operation involving passwords fails to run.
Factory class for creating and checking Password objects.
Represents a password hash for use in authentication.
verify( $password)
Checks whether the given password matches the hash stored in this object.
getType()
Get the type name of the password.
parseHash( $hash)
Perform any parsing necessary on the hash to see if the hash is valid and/or to perform logic for see...
crypt( $password)
Hash a password and store the result in this object.
const MAX_HASH_SIZE
Hash must fit in user_password, which is a tinyblob.
isSupported()
Whether current password type is supported on this system.
needsUpdate()
Determine if the hash needs to be updated.
__construct(PasswordFactory $factory, array $config, $hash=null)
Construct the Password object using a string hash.
assertIsSafeSize( $hash)
Assert that hash will fit in a tinyblob field.
string $hash
String representation of the hash without the type.
equals( $other)
Compare one Password object to this object.
toString()
Convert this hash to a string that can be stored in the database.
array $config
Array of configuration variables injected from the constructor.
PasswordFactory $factory
Factory that created the object.