对于盐和哈希密码,我使用了bcrypt方法,但它显示为错误=新错误('数据和盐参数所需');
对于盐和哈希密码,我使用了bcrypt方法,但它显示了 错误=新错误('需要数据和盐参数'); 我认为我的代码有问题,请我需要帮助; 电子商务网站是我的项目,因此,我在用户面板中创建了注册表
* user.js
const userHelpers=require('../helpers/user-helpers')
router.get('/signup',(req,res)=>{
res.render('user/signup')
})
router.post('/signup',(req,res)=>{
userHelpers.doSignup(req.body).then((response)=>{
console.log(response);
})
user-helpers.js
var db=require('../config/connection')
var collection=require('../config/collections')
const bcrypt=require('bcrypt')
module.exports={
doSignup:(userData)=>{
return new Promise(async(resolve,reject)=>{
// var salt = await bcrypt.genSalt(10);
userData.Password= await bcrypt.hash(userData.Password ,10)
db.get().collection(collection.USER_COLLECTION).insertOne(userData).then((data)=>{
resolve(data)
});
});
}
Collection.js
module.exports={
PRODUCT_COLLECTION:'product',
USER_COLLECTION:'user'
}
这是我的代码,但是错误
error = new Error('data and salt arguments required');
^
Error: data and salt arguments required
如何解决问题。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您遇到的错误,它看起来像
bcrypt.hash
失败,因为userdata.password
可能未设置。确保使用请求正确获取userdata.password。
如果您使用Express,则可能不会转换为JSON,因此请添加中间件将数据解析为JSON,例如:
查看以前的问题&答案:
According to the error you get, it looks like the function
bcrypt.hash
fails becauseuserData.Password
might not be set.Make sure that you get the userData.Password correctly with the request.
If you use express you might not have a conversion to JSON so add a middleware to parse the data to JSON, like:
Take a look at these previous questions & answers:
谢谢,我得到了解决方案。
用户helpers.js
中的问题。用户helpers.js
Thank you, I got the solution. The problem in the
user-helpers.js
.user-helpers.js