Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
66.67% |
4 / 6 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
Pbkdf2PasswordUsingHashExtension | |
80.00% |
4 / 5 |
|
50.00% |
1 / 2 |
4.13 | |
0.00% |
0 / 1 |
getDigestAlgo | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
pbkdf2 | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 |
1 | <?php |
2 | /** |
3 | * Implements the Pbkdf2PasswordUsingHashExtension class for the MediaWiki software. |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | * http://www.gnu.org/copyleft/gpl.html |
19 | * |
20 | * @file |
21 | */ |
22 | |
23 | declare( strict_types = 1 ); |
24 | |
25 | /** |
26 | * A PBKDF2-hashed password, using PHP's hash extension |
27 | * |
28 | * This class exists for compatibility purposes only! Unless an installation's existing |
29 | * password hashes were generated using an algorithm not supported by OpenSSL, or the |
30 | * OpenSSL PHP extension is unavailable, Pbkdf2PasswordUsingOpenSSL should be used. |
31 | * |
32 | * @since 1.40 (since 1.29 under the old name) |
33 | */ |
34 | class Pbkdf2PasswordUsingHashExtension extends AbstractPbkdf2Password { |
35 | protected function getDigestAlgo( string $algo ): ?string { |
36 | return in_array( $algo, hash_hmac_algos(), true ) ? $algo : null; |
37 | } |
38 | |
39 | protected function pbkdf2( |
40 | string $digestAlgo, |
41 | string $password, |
42 | string $salt, |
43 | int $rounds, |
44 | int $length |
45 | ): string { |
46 | $hash = hash_pbkdf2( $digestAlgo, $password, $salt, $rounds, $length, true ); |
47 | // Note: this check is unnecessary in PHP 8.0+, since the warning cases |
48 | // were all converted to exceptions |
49 | '@phan-var string|false $hash'; |
50 | if ( !is_string( $hash ) ) { |
51 | throw new PasswordError( 'Error when hashing password.' ); |
52 | } |
53 | return $hash; |
54 | } |
55 | } |
56 | |
57 | /** @deprecated class alias since 1.40 */ |
58 | class_alias( Pbkdf2PasswordUsingHashExtension::class, 'Pbkdf2Password' ); |