enG*_*izo 3 javascript cryptography blowfish node.js
我想知道如何使用blowfish算法在Node.js中使用salt来散列密码,算法应该是单向的.
看看bcrypt模块(它使用河豚)
https://www.npmjs.org/package/bcrypt
请注意,模块会为您处理salt和哈希的组合,因此一旦生成哈希,您就不必管理存储盐(请注意,compare函数只需要密码,salt隐含在哈希中)
它非常简单(从文档中复制)
async (recommended)
To hash a password:
var bcrypt = require('bcrypt');
bcrypt.genSalt(10, function(err, salt) {
bcrypt.hash("B4c0/\/", salt, function(err, hash) {
// Store hash in your password DB.
});
});
To check a password:
// Load hash from your password DB.
bcrypt.compare("B4c0/\/", hash, function(err, res) {
// res == true
});
bcrypt.compare("not_bacon", hash, function(err, res) {
// res = false
});
Auto-gen a salt and hash:
bcrypt.hash('bacon', 8, function(err, hash) {
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3308 次 |
| 最近记录: |