防止桌面应用程序上出现多个相同的用户登录

时间:2022-08-19 16:47:29

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?

我正在开发一个多用户桌面应用程序。我需要找到一种方法,让每个用户每次只能登录一个用户。基本上,John不能从PC-A登录到应用程序,然后再运行到PC-B并登录。我的想法是设置一个位标志,表示用户已经登录,当从另一个位置进行尝试时,它会通知用户当前的用户名已经登录。这将一直重复,直到PC-A上的John退出系统或手动注销。唯一的问题是,如果应用程序崩溃,则不会调用注销方法。建议吗?

2 个解决方案

#1


2  

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.

如果您既不能优雅地退出应用程序,也不能至少捕获所有异常并适当地处理,我认为惟一的选择就是使用会话方法。基本上,当每个用户登录时,就会建立一个新的会话,而这个会话id将被用来验证将来的任何调用。

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.

通过这样做,当用户试图登录其他地方时,您可以允许使用终止现有/打开会话。如果他们尝试从PC B登录,并且已经从PC A登录,你只需在提示符中输入,如果他们选择继续从PC B登录,PC A上的会话将被禁用。即使有人正在积极使用PC A上的应用程序,当会话结束时,他们发出的下一个服务调用也应该被拒绝。

#2


1  

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

查看MySQL的GET_LOCK()和RELEASE_LOCK()函数。

#1


2  

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.

如果您既不能优雅地退出应用程序,也不能至少捕获所有异常并适当地处理,我认为惟一的选择就是使用会话方法。基本上,当每个用户登录时,就会建立一个新的会话,而这个会话id将被用来验证将来的任何调用。

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.

通过这样做,当用户试图登录其他地方时,您可以允许使用终止现有/打开会话。如果他们尝试从PC B登录,并且已经从PC A登录,你只需在提示符中输入,如果他们选择继续从PC B登录,PC A上的会话将被禁用。即使有人正在积极使用PC A上的应用程序,当会话结束时,他们发出的下一个服务调用也应该被拒绝。

#2


1  

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

查看MySQL的GET_LOCK()和RELEASE_LOCK()函数。