相同的盐,相同的密码,不同的结果(bcrypt)
我正在使用 bcrypt with node.js ,即使每次都会出现不同同样的盐。这是我的代码:
const bcrypt = require('bcrypt');
let saltRounds = 1;
let salt = bcrypt.genSaltSync(saltRounds);
let hash = bcrypt.hashSync('senha', salt);
console.log(hash);
我在做什么错?如何解决这个问题?
I'm using bcrypt with Node.js and the hash comes out different each time, even using the same salt. This is my code:
const bcrypt = require('bcrypt');
let saltRounds = 1;
let salt = bcrypt.genSaltSync(saltRounds);
let hash = bcrypt.hashSync('senha', salt);
console.log(hash);
What am I doing wrong? How to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您每次都在重新生成盐。您必须仅生成一次盐,然后将其与哈希密码一起存储。当需要验证,从存储中提取盐和哈希密码,使用存储的盐哈希输入密码,然后将其与存储的哈希密码进行比较。
You are re-generating the salt each time. You must generate the salt only once, and store it along with the hashed password. When it comes time to validate, pull the salt and the hashed password from storage, hash the input password using the stored salt, and compare to the stored hashed password.