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.
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>
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.