How can I detect a user's computer/browser session for auth purposes

瘦欲@ 提交于 2019-12-25 09:39:40

问题


I am trying to implement a login system that sends a confirmation email to the user in case he logs in from a new computer/browser.

I am using Nodejs, AngularJS and PassportJS.

Any pointers to where I could find resources for this will be greatly appreciated.


回答1:


The client side can detect stuff like os/browser, so you can just POST that data up to the server whenever the client loads. Other than that, you can match usernames with IP-adresses, but if you're storing that kind of information you ought to hash the information before saving it.




回答2:


Could be as simple as setting a session variable (https://github.com/expressjs/session)

if(req.user){ // so that it only triggers when the user has actually logged in
    if(!req.session.thisBrowser) {
        req.session.thisBrowser = true || 'this computer/browser' || 'whatever';
        req.user.email('You have been logged in from ...'); // do your thing
    }
}


来源:https://stackoverflow.com/questions/27464852/how-can-i-detect-a-users-computer-browser-session-for-auth-purposes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!