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

编程入门 行业动态 更新时间:2024-10-09 02:23:47

[从登录<a href=https://www.elefans.com/category/jswz/34/1771438.html style=路径中的数据库检查用户密码"/>

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

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

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

希望对您有所帮助!

更多推荐

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

本文发布于:2024-05-07 11:08:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1755959.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   用户密码   数据库

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!