Skip to content

[PasswordHasher] Generates a PHP fatal error when using auto algorithm  #41571

Closed
@matason

Description

@matason

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions