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 );
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 );