Closed
Description
Symfony version(s) affected: 5.3.x
Description
When using the auto algorithm in the PasswordHasher component outside of a Symfony project, a PHP warning and fatal error is generated:
PHP Notice: Undefined index: hash_algorithm in /symfony/password-hasher/Hasher/PasswordHasherFactory.php on line 119
PHP Fatal error: Uncaught InvalidArgumentException: "class" must be set in {"algorithm":null} in /symfony/password-hasher/Hasher/PasswordHasherFactory.php:86
How to reproduce
- Create a simple project: composer init && composer require symfony/password-hasher
- Create a PHP file with the following code to exercise the PasswordHasher
<?php
require './vendor/autoload.php';
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory;
$factory = new PasswordHasherFactory(
[
'auto' => ['algorithm' => 'auto'],
]
);
$passwordHasher = $factory->getPasswordHasher('auto');
Possible Solution
Check if $config['hash_algorithm']
is set before adding it to the list of algorithms (and prevent a null being added).
Additional context
N/A