Prevent multiple login using the same user name and password

前端 未结 12 2583
栀梦
栀梦 2020-11-29 22:03

I am developing an application that needs to prevent multiple login using the same user name and password.

If it happens on the same machine then obviously we need t

12条回答
  •  被撕碎了的回忆
    2020-11-29 22:18

    Create one table in your database — let's call it [online_users] — with three fields:

    [online_users]
    1. username
    2. login_time
    3. logout_time
    

    Whenever a user logs in, insert the user's name and the login time into [online_users].

    On all pages which require users to log in, place this condition: check [online_users] to see if the user's logout_time is blank or not.

    Whenever a user presses a logout button, set the logout_time in [online_users] for that user's name.

    If someone tries to log in with an active username and password, check for username and logout_time and display a message stating that the user is already logged in. And, most importantly, set logout_time to MULTIPLELOGIN for that user.

    If that user is logged in on any other machine, then if he refreshes or navigates to another page the site will tell him that he has been logged out. Then, the user can be redirected to the homepage of the site.

提交回复
热议问题