3 use 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 );
75 public function crypt( $password ) {
77 $this->hash = password_hash( $password, $algo,
$params );
84 if ( is_string( $other ) ) {
85 return $this->
verify( $other );
95 public function verify( $password ) {
96 Assert::parameterType(
'string', $password,
'$password' );
98 return password_verify( $password, $this->hash );
105 $res =
":argon2:{$this->hash}";
115 return password_needs_rehash( $this->hash, $algo,
$params );