我看有些文章说 salt 需要存到数据库。
但有些加密库不需要,比如 bcryptjs 。
https://github.com/dcodeIO/bcrypt.js#usage---sync
用法为:
To hash a password:
var bcrypt = require('bcryptjs');
var salt = bcrypt.genSaltSync(10);
var hash = bcrypt.hashSync("B4c0/\/", salt);
// Store hash in your password DB.
To check a password:
// Load hash from your password DB.
bcrypt.compareSync("B4c0/\/", hash); // true
bcrypt.compareSync("not_bacon", hash); // false
Auto-gen a salt and hash:
var hash = bcrypt.hashSync('bacon', 8);
这是什么原理?
我猜它是不是给明文密码又哈希了一次,作为 salt 。因为可以通过明文密码计算出 salt ,所有 salt 不需要入库。
如果确实这是这样,大家认为这两种做饭各有什么优缺点?
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.