I'm trying to implement a secure user authentication by following this website. But I'm having trouble storing the string result from php password_hash function. I mean, this works perfectly:
$pass = "anypassyouwant";
$stored = password_hash(
base64_encode(
hash('sha256', $pass, true)
),
PASSWORD_DEFAULT
);
// ...
if (password_verify(
base64_encode(
hash('sha256', $pass, true)
),
$stored
)) {
echo "TRUE";
} else {
echo "FALSE";
}
In the real app I store "$stored" in my DB and use it to in password_verify, but all I get is a false. Since the above code works perfectly, the only reasonable explanation is the storage in the DB. Varchar and binary are not working.
Does anyone know how should I store it?
Thanks in advance.
My insert instruction:
$sql = sprintf("
INSERT INTO tbl_usuarios (nombre, apellidos, password, email, fechanac, url_in, sexo)
VALUES ('%s', '%s', '%s', '%s', '%s', '%s', %u)",
$nombre,
$apellidos,
$pass,
$bd->escape($_POST['email']),
$fechanac,
$url_in,
$sexo
);
Where pass is the result of password_hash. I tried %s and %b (varchar and binary in the db).