Symfony 2.8 - hash_equals(): Expected known_string to be a string

1.8k Views Asked by At

I've updated symfony from 2.7 to 2.8 and get info from few users (of course for me everything is working fine) that they can't log in. The error message is:

11921#11921: *37980489 FastCGI sent in stderr: "PHP message: PHP Warning:  hash_equals(): Expected known_string to be a string, null given in /www/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Encoder/BasePasswordEncoder.php on line 84" while reading response header from upstream, client: xx.xx.xxx.xx, server: domain.com, request: "POST /action/login HTTP/1.1", upstream: "fastcgi://127.0.0.1:9001", host: "domain.com"

Php version is 7.0.19 (but it didn't change in update).

Security.yml

security:
    encoders:
        Acme\Entity\Frontuser:
            algorithm: sha512

providers:
    acme_db:
        entity:
            class: Acme\Entity\Frontuser

Controller

/**
 * @Route("/action/login", name="gologin", options={"expose"=true})
 */
public function loginAction(Request $request)
{

    $authenticationUtils = $this->get('security.authentication_utils');

    // get the login error if there is one
    $error = $authenticationUtils->getLastAuthenticationError();

    // last username entered by the user
    $lastUsername = $authenticationUtils->getLastUsername();

    return $this->render(
        'Acme:Security:Form.html.twig',
        [
            'last_username' => $lastUsername,
            'login_error' => $error,
        ]
    );
}

Form.html.twig

<form id="form-login" method="post" class="form-horizontal" action="{{ path('gologin') }}">
<div>
    <label for="modal-login-email">{{ 'email'|capitalize }}</label>
    <input type="email" autocomplete="email" name="_username" value="{{ last_username|default() }}" id="modal-login-email" required>
</div>
<div>
    <label for="modal-login-password">{{ 'password'|trans|capitalize }}</label>
    <input type="password" name="_password" id="modal-login-password" required>
</div>
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
<button id="login-button" type="submit">{{ 'login'|trans }}</button>

And using ajax login made similar to this https://www.brainvire.com/add-ajax-login-form-symfony2-project/. Can anyone try to help/understand this?

1

There are 1 best solutions below

1
On
$hash_equals = $known_string != '' ? hash_equals( $known_string, $user_string ) : false;
            
if ( $hash_equals ) {
    return true;
}