簡體   English   中英

這種快速會話身份驗證方法安全嗎?

[英]Is this express-session authentication method secure

我不確定此express-session auth方法是否安全。 我使用bcryptjs加密密碼,並在加密后在req.session.isLoggedIn = true設置req.session.isLoggedIn = trueadmin.js使用if語句在events.jsevents.js進行檢查。 events.js的if語句方法安全嗎? 有更好的選擇嗎? 我正在使用把手來渲染網頁。

admin.js

bcrypt.compare(pass, user.password).then((doMatch) => {
    console.log(doMatch);
    //Check if password match
    if (doMatch) {
      //setting the isLoggedIn value
      req.session.isLoggedIn = true;
      //Events is the route that requires authentication
      return res.redirect('/events');
    } else {
      res.redirect('/');
    }
  }).catch((err) => {
    console.log(err);
  });

events.js

Router.get('/', (req, res) => {
//Checking the if the loggedIn value is true
if (req.session.isLoggedIn) {
Event.find({}, (err, events) => {
  res.render('events', {
    prods: events,
    pageTitle: 'Events',
    path: '/events',
    hasProducts: events.length > 0
  });
}).catch((err) => {
  console.log(err);
});
} else {
  console.log('User not authenticated');
  res.status(404).send({error: 'not authorized!'});
}

});

我認為這不是您應該查看的最佳方法: http : //www.passportjs.org/

他們有關於身份驗證策略和注冊的良好文檔,還有許多其他方法(Facebook登錄,Twitter ...),還有許多關於如何實現Passport.js的教程。

希望對您有幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM