2
我想使用node.js bcrypt在将密码存储到数据库之前对密码进行哈希处理。为什么不用盐来比较密码在bcrypt中是否正确?
此链接提供了文档。 https://github.com/kelektiv/node.bcrypt.js
这里是一个哈希密码的例子。
var bcrypt = require('bcrypt');
const saltRounds = 10;
const myPlaintextPassword = 's0/\/\P4$$w0rD';
var salt = bcrypt.genSaltSync(saltRounds);
var hash = bcrypt.hashSync(myPlaintextPassword, salt);
// Store hash in your password DB.
这是检查密码的代码。
// Load hash from your password DB.
bcrypt.compareSync(myPlaintextPassword, hash); // true
这是我不明白。在bcrypt.compareSync
,为什么没有参数salt
?由于哈希是从salt生成的,为什么比较明文密码不涉及哈希中使用的原始盐?
感谢答案。如果salt是生成的哈希的一部分,那么会不会使得bcrypt不那么安全? – user781486
不,它没有。盐总是必须可用,用散列存储它,或者单独对安全性没有影响。盐的目的是防止彩虹桌攻击,为此目的,如果攻击者拥有盐,这不是问题。 – Tom