Prevent Multiple Same User Logins On A Desktop App

2020-07-22 19:36发布

I'm developing a multi-user desktop application. I need to figure out a way to allow only one user to login at a time per username. Basically, John can't login to the application from PC-A and then run over to PC-B and login as well. What I had in mind was to set up a bit flag that indicated that a user has logged in and when an attempt is made from another location that it would advise the user that the current username is already logged in. This would repeat until John on PC-A either exits the system or manually logs out. The only issue is if the application crashes, no logout method is called. Suggestions?

2条回答
等我变得足够好
2楼-- · 2020-07-22 19:46

Look into the GET_LOCK() and RELEASE_LOCK() functions for MySQL.

查看更多
唯我独甜
3楼-- · 2020-07-22 19:52

If you can't depend on either gracefully exiting the application or at least capturing all exceptions and handling appropriately, I think the only alternative would be to go to a session approach. Basically, as each user logs in, a new session is established and it's that session id that will be validated against for any future calls.

By doing this, you can allow the use to terminate an existing/open session when they attempt to login somewhere else. If they attempt to login from PC B and are already logged in from PC A - you simply put that in a prompt and if they elect to continue from PC B, the session on PC A is deactivated. Even if someone is actively using the app on PC A, the next service call they issue should be rejected as the session is closed.

查看更多
登录 后发表回答