Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / password / Pbkdf2PasswordUsingHashExtension.php
blob2ecb87ff7b1169fe0c4d3a8e9cde9e5e403448ae
1 <?php
2 /**
3 * Implements the Pbkdf2PasswordUsingHashExtension class for the MediaWiki software.
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.
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.
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
20 * @file
23 declare( strict_types = 1 );
25 namespace MediaWiki\Password;
27 /**
28 * A PBKDF2-hashed password, using PHP's hash extension
30 * This class exists for compatibility purposes only! Unless an installation's
31 * existing password hashes were generated using an algorithm not supported by
32 * OpenSSL, Pbkdf2PasswordUsingOpenSSL should be used.
34 * @since 1.40 (since 1.29 under the old name)
36 class Pbkdf2PasswordUsingHashExtension extends AbstractPbkdf2Password {
37 protected function getDigestAlgo( string $algo ): ?string {
38 return in_array( $algo, hash_hmac_algos(), true ) ? $algo : null;
41 protected function pbkdf2(
42 string $digestAlgo,
43 string $password,
44 string $salt,
45 int $rounds,
46 int $length
47 ): string {
48 $hash = hash_pbkdf2( $digestAlgo, $password, $salt, $rounds, $length, true );
49 // Note: this check is unnecessary in PHP 8.0+, since the warning cases
50 // were all converted to exceptions
51 '@phan-var string|false $hash';
52 if ( !is_string( $hash ) ) {
53 throw new PasswordError( 'Error when hashing password.' );
55 return $hash;
59 /** @deprecated class alias since 1.40; use MediaWiki\\Password\\Pbkdf2PasswordUsingHashExtension */
60 class_alias( Pbkdf2PasswordUsingHashExtension::class, 'Pbkdf2Password' );
62 /** @deprecated since 1.43 use MediaWiki\\Password\\Pbkdf2PasswordUsingHashExtension */
63 class_alias( Pbkdf2PasswordUsingHashExtension::class, 'Pbkdf2PasswordUsingHashExtension' );