Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

pasword_hash($password) is null

I have an problem with the pasword_hash function in PHP.

The following Snippet is in use:

// Passwort darf nicht leer sein
if (empty($password)) {
    echo "Dieses Feld darf nicht leer sein!";
    $error = true;
}

$passw = password_hash($password);
// Begin der Registrierung
if (!$error) {
    $registerService = new RegisterService();
    try {
        echo "<pre>";
        var_dump($passw);
        echo "</pre>";
        die();
        $session = $registerService->insertRegisteredUser($username, $password);
        echo json_encode(array("success" => 1));
    } catch (Exception $e) {
        echo json_encode(array("success" => 0));
    }
}

The output of the vardump is null. The password string ist definitve not empty or null. I dont understand why the function returns null. I use the same function in my login logic, without any problems.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Response of the PHP:

<pre><pre class='xdebug-var-dump' dir='ltr'>
<small>/var/www/lernapp/src/register.php:31:</small><font color='#3465a4'>null</font>
</pre></pre>

>Solution :

You should be getting an exception reported. Given that you are not I assume you have all exception reporting disabled.

https://3v4l.org/4S1Bu#v8.1.10

password_hash() requires 2 parameters, the thing you want to hash and an algorithm you want to use.

https://3v4l.org/D662K#v8.1.10

Docs: https://www.php.net/manual/en/function.password-hash

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading