【发布时间】:2016-11-04 12:05:47
【问题描述】:
我正在使用 yortus 的 async/await node.js 库来设置基于 Passport 的登录/注册系统,密码使用 bcrypt-nodejs 散列。
虽然系统的其余部分已设置并正常运行,但我无法让 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。我已经尝试了许多排列和组合但没有成功,感谢任何帮助。
【问题讨论】:
标签: javascript node.js asynchronous passport.js bcrypt