最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

[从登录路径中的数据库检查用户密码

IT培训 admin 12浏览 0评论

[从登录路径中的数据库检查用户密码

**一天的大部分时间!我只是尝试通过用户的电子邮件来检查登录用户,如果有这样的电子邮件,那么它应该检查数据库中密码的正确性,我只是停止了密码检查,对此提供了帮助!

    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);
    }
})

希望对您有所帮助!

[从登录路径中的数据库检查用户密码

**一天的大部分时间!我只是尝试通过用户的电子邮件来检查登录用户,如果有这样的电子邮件,那么它应该检查数据库中密码的正确性,我只是停止了密码检查,对此提供了帮助!

    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);
    }
})

希望对您有所帮助!

发布评论

评论列表 (0)

  1. 暂无评论