如何在Windows应用程序C#中防止同一用户多次登录?

问题描述:

亲爱的所有人,



我在asp.net C#和数据库SQL服务器上构建了Web和Windows应用程序。



我想阻止用户使用相同的用户ID /密码登录Windows应用程序。



用户同时登录Windows应用程序同时使用相同的用户ID和密码,但不同的机器。



我尝试过:



我尝试将登录用户的状态更新为LoggedIn,但这是同时从同一用户的两台计算机更新。



如何防止用户多次登录?



任何人都可以帮助我。





提前谢谢

Dear All,

I have Web and windows application build in asp.net C# and database SQL server.

I would like to stop a user(s) to login into the windows application with the same UserID/Password.

The users are simultaneously login into the windows application with the same UserID and password at the same time but different machines.

What I have tried:

I tried to update the status of logged in user as 'LoggedIn' but this is updating at the same time from two machines for the same user.

How can I prevent a user from multiple logins?

Can anyone please help me.


Thanks in advance

我发现阻止用户多次登录的最佳方法是允许他们登录但警告他们他们将从其他机器登出,然后如果他们接受,请记录下来。



我不知道如何实现这一点,因为你没有提供任何代码,但希望这种方法对你有用。 br $>


FYI:如果实例崩溃,这也需要检查注销过程
I have found that the best way to prevent multiple logins for a user is to allow them to log in but warn them that they will be logged out of other machines, then log them out if they accept.

I have no idea how you would implement this as you have not given any code, but hopefully the approach will work for you.

FYI: this also takes care of not having to check the logout process if an instance crashes


你应该再创建一个表名字 activeLogin 有下面提到的栏目



RefID,Key,LoginTime,LogoutTime, IsActive



您可以在安装应用程序时生成自定义密钥,或者在运行应用程序时,可以根据登录时间进行保存。 br />


该密钥可以是主板,自定义密钥存储为 .ini 文件或任何其他配置文件。



您可以在执行应用程序的登录活动时在表中进行检查。如果Logout列为NULL并且IsActive = true并且ket不同,那么您可以提示您确定要登录吗?然后你应该设置Logout = GetDate()和IsActive = false,这将带来新的密钥和时间在activelogin表中的新记录。



所以你可以检查一下具有常规时间间隔的密钥,例如1或2分钟,如果找不到应该激活的相应密钥,则可以关闭应用程序
You should create one more table having name activeLogin with bellowed mentioned columns

RefID, Key, LoginTime, LogoutTime, IsActive

You can generate custom key while installing the application or while running the applicatio, you can save it with respect to login time.

That key can be anything like motherboard, custom key stored as .ini file or any other config file.

You can check it in the table while doing a login activity of an application. If the Logout column is NULL and IsActive = true and the ket is different then you can prompt "Are you sure want to login ?" then you should Set Logout = GetDate() and IsActive = false, This will leads new record in activelogin table with new key and time.

So You can to check that key with regular time interval like 1 or 2 min, If you can't find respective key which should be active then you can shutdown the app