3use Wikimedia\Assert\Assert;
35 'memory_cost' =>
null,
45 return defined(
'PASSWORD_ARGON2I' ) || defined(
'PASSWORD_ARGON2ID' );
52 switch ( $this->config[
'algo'] ) {
54 $algo = PASSWORD_ARGON2I;
57 $algo = PASSWORD_ARGON2ID;
60 $algo = defined(
'PASSWORD_ARGON2ID' ) ? PASSWORD_ARGON2ID : PASSWORD_ARGON2I;
63 throw new LogicException(
"Unexpected algo: {$this->config['algo']}" );
67 $params = array_intersect_key( $this->config, self::$knownOptions );
69 return [ $algo, $params ];
75 public function crypt( $password ) {
77 $this->hash = password_hash( $password, $algo, $params );
86 if ( is_string( $other ) ) {
87 return $this->
verify( $other );
97 public function verify( $password ) {
98 Assert::parameterType(
'string', $password,
'$password' );
100 return password_verify( $password, $this->hash );
107 $res =
":argon2:{$this->hash}";
117 return password_needs_rehash( $this->hash, $algo, $params );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Implements Argon2, a modern key derivation algorithm designed to resist GPU cracking and side-channel...
toString()
Convert this hash to a string that can be stored in the database.The resulting string should be consi...
equals( $other)
Compare one Password object to this object.By default, do a timing-safe string comparison on the resu...
needsUpdate()
Determine if the hash needs to be updated.bool True if needs update, false otherwise
crypt( $password)
Hash a password and store the result in this object.The result of the password hash should be put int...
isSupported()
Whether current password type is supported on this system.bool
verify( $password)
Checks whether the given password matches the hash stored in this object.bool
static null[] $knownOptions
Array with known password_hash() option names as keys.
Represents a password hash for use in authentication.
assertIsSafeSize( $hash)
Assert that hash will fit in a tinyblob field.