如何使用密码散列最近,我一直试图在网上偶然发现的登录脚本上实现自己的安全性。在努力学习如何让自己的脚本为每个用户生成一个SALT之后,我无意中发现了Password_Hash。根据我所理解的(基于本页的阅读):http://php.net/manual/en/faq.passwords.php),当使用Password_Hash时,已在行中生成SALT。这是真的吗?我的另一个问题是,吃两种盐不是很明智吗?一个直接在文件里,一个在数据库里?这样的话,如果有人在DB中妥协了您的盐分,那么您仍然可以直接在文件中找到盐吗?我在这里读到,储存盐从来不是一个聪明的想法,但它总是混淆了人们的意思。
3 回答
慕田峪7331174
TA贡献1828条经验 获得超13个赞
password_hash
$password = $_POST['password'];
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
var_dump($hashed_password);
// Query the database for username and password// ...if(password_verify($password, $hashed_password)) { // If the password inputs matched the hashed password in the database // Do something, you know... log them in.} // Else, Redirect them back to the login page.
烙印99
TA贡献1829条经验 获得超13个赞
// 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);
小怪兽爱吃肉
TA贡献1852条经验 获得超1个赞
password_hash()
使用的算法 参数 食盐 实际密码散列
- 3 回答
- 0 关注
- 524 浏览
添加回答
举报
0/150
提交
取消