路径中的数据库检查用户密码"/>
[从登录路径中的数据库检查用户密码
**一天的大部分时间!我只是尝试通过用户的电子邮件来检查登录用户,如果有这样的电子邮件,那么它应该检查数据库中密码的正确性,我只是停止了密码检查,对此提供了帮助!
const mail = req.body.e_mail;
const pw = req.body.password;
RegData.findOne({e_mail: mail}, function(error, foundUser) {
if(!error) {
if (foundUser) {
/* if there is a user with correct e_mail, then check he's password: if correct send('content page'), else send('check your reg-data') */
} else {
res.send("you've not been registered yet")
}
} else {
res.send(error);
}
})
回答如下:您要做的就是比较提供的密码和数据库中保存的其他密码之间的密码,但是建议在保存之前对密码进行哈希处理
const mail = req.body.e_mail;
const pw = req.body.password;
RegData.findOne({e_mail: mail}, function(error, foundUser) {
if(!error) {
if (foundUser) {
//----compare passwords-----//
if (foundUser.password==pwd){ //password matches
req.send('content page')
}else{
req.send('check your reg-data')
}
//---end checking password compraison
} else {
res.send("you've not been registered yet")
}
} else {
res.send(error);
}
})
希望对您有所帮助!
更多推荐
[从登录路径中的数据库检查用户密码
发布评论