My question began when I decided to re-examine the method I was using to obtain the user's password and store it in the database. After reading this , this and this question here on the net, plus many others on other networks, such as this and this ,
We have old yet excellent methods to the present day of generating a hash to store in BD . We also have some, which were considered to be optimal, but which are already falling into disuse (or at least in concept) due to security, as is the case of md5
and sha
family.
We also have new methods where, as far as I read, it seems to be the strongest candidate to be used for hash generation, even more recommended than bcrypt
or PBKDF2
itself is the case of password_*
in PHP >= 5.5
.
Some requirements that I observed to be ideal in crafting hash
-
All hash should be created next to a salt ;
- All salt generated must be unique per client;
- The function should be slow, to make it harder to attack brute force;
With that in mind, how far can I consider this thinking to be correct and start using only the password_*
method? Would it fit into the ideal requirements for hash generation ?
What caught my attention was also the simplicity in terms of the code to use password_*
, because with a few lines of code we can get the expected result, for example:
//Gerar um hash
$salt = $resultadoSalt; //resultado de uma função para obter o salt único
$options = [
'cost' => 14,
'salt' => $salt
];
$hash = password_hash($password, PASSWORD_BCRYPT, $options);
//Validar um hash
if (!password_verify($password, $hash)) return false;
In this case, would it be enough to store the result of the password_hash
function in the Database? Eg: $2y$14$5e7b5f0ef3cccfac9b902uR4sHJTlTYv3RYt3ApP7PvyTXHmdhN7e
or some other process would be recommended?
Remembering that any other considerations on the subject are welcome!