3
I have a simple question about encryption using bcrypt with salt.
When in old projects I used md5, to check in a login form if the user typed the correct password and authenticate, it was customary to take the value that the user typed and encrypt in md5 and search in the bd.
But as in bcrypt using random salt does not to do this, so I did the following:
I take the email or Cpf that the user typed in the login field, look in the bd for the corresponding record and use the password stored in the bd(hash) as salt and the password entered by the user as the string in the crypt($string, $salt) function and the return of the function compares with the password stored in the bd, and by logic the function must generate exactly the hash itself.
Follow a piece of my code just so you’ll understand better what I’m talking about
//Exemplo da busca com cpf
$buscar = $con->prepare("SELECT * FROM usuarios WHERE cpf =:cpf");
$buscar->bindValue(":cpf", $login);
$buscar->execute();
$row = $buscar->fetch();
//Armazena a senha que esta no bd
$senha_armazenada = $row['senha'];
//Comparação que estou fazendo
if(crypt($senha_digitada, $senha_armazenada) === $senha_armazenada)
And it’s working, but I want to know if it’s the right way to do it.
I’ve been reading the php documentation about password_hash and it contains the following information about PASWORD_DEFAULT "Note that this constant is designed to change over time as new and stronger algorithms are added to PHP". Given the information contained in this excerpt of the documentation, wouldn’t it be better to always use PASSWORD_DEFAULT instead of using some specific algorithm? Since php will always keep the most effective algorithm as standard?
– Leandro Silva Campos
They will always take an entire version to change, if really change. They can only do this in PHP version 7.3 and not in PHP 7.2, which will already have these features. I believe it’s better that you choose than wait for others to choose for you, but there’s already a question about it here.
– Inkeliz