MediaWiki  1.34.0
Pbkdf2Password.php
Go to the documentation of this file.
1 <?php
32  protected function getDefaultParams() {
33  return [
34  'algo' => $this->config['algo'],
35  'rounds' => $this->config['cost'],
36  'length' => $this->config['length']
37  ];
38  }
39 
40  protected function getDelimiter() {
41  return ':';
42  }
43 
44  public function crypt( $password ) {
45  if ( count( $this->args ) == 0 ) {
46  $this->args[] = base64_encode( random_bytes( 16 ) );
47  }
48 
49  $hash = hash_pbkdf2(
50  $this->params['algo'],
51  $password,
52  base64_decode( $this->args[0] ),
53  (int)$this->params['rounds'],
54  (int)$this->params['length'],
55  true
56  );
57  if ( !is_string( $hash ) ) {
58  throw new PasswordError( 'Error when hashing password.' );
59  }
60 
61  $this->hash = base64_encode( $hash );
62  }
63 }
Pbkdf2Password\getDelimiter
getDelimiter()
Returns the delimiter for the parameters inside the hash.
Definition: Pbkdf2Password.php:40
Pbkdf2Password
A PBKDF2-hashed password.
Definition: Pbkdf2Password.php:31
PasswordError
Show an error when any operation involving passwords fails to run.
Definition: PasswordError.php:26
Pbkdf2Password\getDefaultParams
getDefaultParams()
Return an ordered array of default parameters for this password hash.
Definition: Pbkdf2Password.php:32
Password\$hash
string $hash
String representation of the hash without the type.
Definition: Password.php:71
Pbkdf2Password\crypt
crypt( $password)
Hash a password and store the result in this object.
Definition: Pbkdf2Password.php:44
ParameterizedPassword
Helper class for password hash types that have a delimited set of parameters inside of the hash.
Definition: ParameterizedPassword.php:38