相同的盐,相同的密码,不同的结果(bcrypt)

发布于 2025-02-10 05:07:10 字数 366 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你怎么这么可爱啊 2025-02-17 05:07:10

您每次都在重新生成盐。您必须仅生成一次盐,然后将其与哈希密码一起存储。当需要验证,从存储中提取盐和哈希密码,使用存储的盐哈希输入密码,然后将其与存储的哈希密码进行比较。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文