How can I prevent multiple users from being logged in at the same time with a single user ID?
I searched the internet and found some ways, but they do not work in these situations:
- If JavaScript in the browser is turned off.
- If the user does not click "logout" and instead directly closes the browser.
Suggestions would be appreciated. Thanks.
There could be several possibilities. A quick response is:
Maintain a flag in database; upon every login/out update the flag. For instance, upon every authentication request you can reject the login request if the flag is already true.
Alternatively, you can maintain a list of users in the
Applicationobject and use.Containsto see if it already exists.–EDIT–
Lets try the database flag option; and assume that you have a method called
StillLoggedIn(User)that updates the date/time and flag.So, when user logs in:
For subsequent requests, the app would call
StillLoggedIn(User);Prepare a windows service that would browse the database from time to time(lets say after 5 minutes if you have 10000 users). The service would compare the database date/time with the current date/time and mark the flag as
0if the currentTime minus lastUsedTime is greater than, lets say, 5 minutes.It could be anything besides a database and windows service.