我正在使用yortus'async/await node.js库来设置基于Passport的登录/注册系统,并使用密码散列使用bcrypt-nodejs。设置bcrypt以使用Passport和异步等待Node.js库
而系统的其余部分是安装并正常工作,我遇到了麻烦bcrypt-nodejs
与yortus' async/await
很好地工作,因为bcrypt哈希函数签名需要两个回调和目前还不清楚如何与async/await
使用它。 ..
hash(data, salt, progress, cb)
data - [REQUIRED] - the data to be encrypted.
salt - [REQUIRED] - the salt to be used to hash the password.
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.
error - First parameter to the callback detailing any errors.
result - Second parameter to the callback providing the encrypted form.
的async/await
电话...
let generateHash = async((password) => {
let salt = await(bcrypt.genSaltAsync(10)) // this works
let result = await(bcrypt.hash(password, salt, null)
return result // returns NULL
})
输出:
Unhandled rejection No callback function was given.
数据库条目(MongoDB的),当我尝试使用该系统注册:
{
"_id" : ObjectId("581bf7031386f167a09851b9"),
"username" : "vjk2005",
"password" : ""
}
用户名经历,但密码是NULL
。我尝试了一些排列组合和没有成功,任何帮助表示赞赏。
。我会保留和谐和巴贝尔作为我的最后手段。 – vjk2005