MediaWiki  master
MWSaltedPassword.php
Go to the documentation of this file.
1 <?php
23 declare( strict_types = 1 );
24 
33  protected function getDefaultParams(): array {
34  return [];
35  }
36 
37  protected function getDelimiter(): string {
38  return ':';
39  }
40 
41  public function crypt( string $plaintext ): void {
42  if ( count( $this->args ) == 0 ) {
43  $this->args[] = MWCryptRand::generateHex( 8 );
44  }
45 
46  $this->hash = md5( $this->args[0] . '-' . md5( $plaintext ) );
47 
48  if ( !is_string( $this->hash ) || strlen( $this->hash ) < 32 ) {
49  throw new PasswordError( 'Error when hashing password.' );
50  }
51  }
52 }
MWSaltedPassword\getDelimiter
getDelimiter()
Returns the delimiter for the parameters inside the hash.
Definition: MWSaltedPassword.php:37
PasswordError
Show an error when any operation involving passwords fails to run.
Definition: PasswordError.php:29
MWSaltedPassword\getDefaultParams
getDefaultParams()
Return an ordered array of default parameters for this password hash.
Definition: MWSaltedPassword.php:33
MWSaltedPassword
The old style of MediaWiki password hashing, with a salt.
Definition: MWSaltedPassword.php:32
MWCryptRand\generateHex
static generateHex( $chars)
Generate a run of cryptographically random data and return it in hexadecimal string format.
Definition: MWCryptRand.php:36
ParameterizedPassword
Helper class for password hash types that have a delimited set of parameters inside of the hash.
Definition: ParameterizedPassword.php:40
MWSaltedPassword\crypt
crypt(string $plaintext)
Hash a password and store the result in this object.
Definition: MWSaltedPassword.php:41