我显然是刚开始使用河豚加密技术来问这个问题。我相信有一个方程的一边,但不知道如何登录一旦哈希是在DB。我有以下在注册时加密密码的方法:
$blowfish_hash = "$2y$10$";
$salt_length = 22;
$salt = Generate_Salt($salt_length);
$hash_combined = $blowfish_hash . $salt;
$hash = crypt($password, $hash_combined);
$password = $hash;Generate_Salt()函数如下:
function Generate_Salt($length) {
$unique_rndm_str = md5(uniqid(mt_rand(), true));
$base64_string = base64_encode($unique_rndm_str);
$mod_Base64_str = str_replace('+', '.', $base64_string);
$salt = substr($mod_Base64_str, 0, $length);
return $salt;
}一旦我注册,我就会得到这个很好的长哈希-太棒了!但是,当我登录时,我不确定如何调用哈希来检查给定的密码:$_POST['log_password'];
使用md5是很容易的,我只是用这种方式加密了$password = md5($password);,并以这种方式回忆起了$password = md5($_POST['log_password']);,但是我发现这不是一种安全的方法。
我已经干了好几个小时了,有人能帮我解释一下吗?任何帮助都将不胜感激。
ep
发布于 2018-03-21 12:14:04
这比你想象的要容易得多。只需使用函数散列(),它将执行对crypt()函数的调用并处理安全盐的生成。
// Hash a new password for storing in the database.
// The function automatically generates a cryptographically safe salt.
$hashToStoreInDb = password_hash($_POST['password'], PASSWORD_DEFAULT);
// Check if the hash of the entered login password, matches the stored hash.
// The salt and the cost factor will be extracted from $existingHashFromDb.
$isPasswordCorrect = password_verify($_POST['password'], $existingHashFromDb);https://stackoverflow.com/questions/49404502
复制相似问题