`
CindyLiao
  • 浏览: 12565 次
  • 性别: Icon_minigender_2
  • 来自: 广州
文章分类
社区版块
存档分类
最新评论

bcrypt-node 替换 bcrypt

阅读更多
npm install bcryp --save 安装不成功,所以
用bcrypt-node.js来替换bcrypt,但是bcrypt-node的hash参数有四个
function hash(data, salt, progress, callback) {
/*
data - [REQUIRED] - the data to be encrypted.
salt - [REQUIRED] - the salt to be used to hash the password. if specified as a number then a salt will be generated and used (see examples).
progress - a callback to be called during the hash calculation to signify progress
callback - [REQUIRED] - a callback to be fired once the data has been encrypted. uses eio making it asynchronous.
error - First parameter to the callback detailing any errors.
encrypted - Second parameter to the callback providing the encrypted form.
*/
比bcrypt多了一个progress参数,该参数是一个回调函数

解决方法:
在bcrypt-node.js 的function hash(data, salt, progress, callback) 方法中加入
if(typeof  callback == 'undefined') {
callback = progress;
progress = null;
}
而别的模块调用hash的时候progress参数设置为null即可,
bcrypt.hash(user.password, salt,null, function(err, hash)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics