MediaWiki master
Pbkdf2PasswordUsingOpenSSL.php
Go to the documentation of this file.
1<?php
9declare( strict_types = 1 );
10
11namespace MediaWiki\Password;
12
22 private static $digestAlgos;
23
40 private const DIGEST_ALGOS = [
41 'sha256' => 'sha256',
42 'sha512' => 'sha512',
43 ];
44
45 protected function getDigestAlgo( string $algo ): ?string {
46 if ( self::$digestAlgos === null ) {
47 self::$digestAlgos = array_intersect( self::DIGEST_ALGOS, openssl_get_md_methods() );
48 }
49 return self::$digestAlgos[$algo] ?? null;
50 }
51
52 protected function pbkdf2(
53 string $digestAlgo,
54 string $password,
55 string $salt,
56 int $rounds,
57 int $length
58 ): string {
59 // Clear error string
60 while ( openssl_error_string() !== false );
61 $hash = openssl_pbkdf2( $password, $salt, $length, $rounds, $digestAlgo );
62 if ( !is_string( $hash ) ) {
63 throw new PasswordError( 'Error when hashing password: ' . openssl_error_string() );
64 }
65 return $hash;
66 }
67}
68
70class_alias( Pbkdf2PasswordUsingOpenSSL::class, 'Pbkdf2PasswordUsingOpenSSL' );
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:68
Show an error when any operation involving passwords fails to run.
pbkdf2(string $digestAlgo, string $password, string $salt, int $rounds, int $length)
Call the PBKDF2 implementation, which hashes the password.
getDigestAlgo(string $algo)
Get the implementation specific name for a hash algorithm.