MediaWiki REL1_34
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}
Helper class for password hash types that have a delimited set of parameters inside of the hash.
Show an error when any operation involving passwords fails to run.
string $hash
String representation of the hash without the type.
Definition Password.php:71
A PBKDF2-hashed password.
crypt( $password)
Hash a password and store the result in this object.
getDefaultParams()
Return an ordered array of default parameters for this password hash.
getDelimiter()
Returns the delimiter for the parameters inside the hash.