微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

除bcrypt之外的一种比较密码的方法

如何解决除bcrypt之外的一种比较密码的方法

大家好,我目前正在使用身份验证表格,但遇到问题

我的注册路线

`app.post("/signup",function(req,res){`

User.register({username:req.body.username},req.body.password,function(err,registeredUser){

if(err){

req.flash("error",err.message);


  res.locals.message = req.flash();


  return res.render("signup")


}else{


 passport.authenticate("local")(req,res,function(){
  

res.redirect("/secrets")


})


 }

})

})

我的登录路线

app.post("/login",res){


const user = new User({


 username:req.body.username,password:req.body.password



 })






if(user.username === ""){


   req.flash("error","Username is required");


  res.locals.message = req.flash();
    


 }else if(user.password === ""){
  req.flash("error","The password field is empty");


 res.locals.message = req.flash();
  return res.render("login")

}其他{

req.login(user,function(err){

`User.findOne({username:req.body.username},function(err,foundUser){

  if(foundUser){
    

passport.authenticate("local",{failureRedirect:"/login"})(req,function(){
   

   res.redirect("/secrets")
          
   

 })





  } else{
      

 req.flash("error","Incorrect email or password");
     

  res.locals.message = req.flash();
       

return res.render("login")


  }


  }


})


  }

})

我能够在登录时检查用户名字段和密码字段是否均为空以及数据库中是否没有用户 但是问题是当我的用户存在并且密码错误时,我的逻辑无法捕获它 有没有一种方法可以比较哈希密码和盐腌密码与用户当前键入的密码以提供适当的错误代码,即密码对于给定的用户名不正确 谢谢...

解决方法

如果使用bcrypt进行哈希运算,则无法在没有bcrypt的情况下比较两个密码

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。