简体   繁体   English

禁用基于Web的应用程序的多个用户登录

[英]Disable multiple user login for web based application

I'm creating a web based application that requires people to register and login for access to certain pages. 我正在创建一个基于Web的应用程序,要求人们注册并登录以访问某些页面。 I want to stop users from giving out their username/password to other people by denying access to more than one person using the same username at the same time. 我想阻止用户通过拒绝同时使用相同的用户名访问多个人来向其他人提供用户名/密码。

Don't know if its a great solution but you can keep a bit in users table and set it to 1 when user is logged in. And check it before login, if its set don't allow more logins by other users. 不知道它是否是一个很好的解决方案,但你可以在用户表中保留一点,并在用户登录时将其设置为1.如果其设置不允许其他用户进行更多登录,请在登录前进行检查。 On logout function unset this bit. 注销功能取消设置此位。

In spring security , we can able to manage user login like this, spring security ,我们可以像这样管理用户登录,

<session-management>
    <concurrency-control max-sessions="1"/>
</session-management>

So when the time user logged in, you will gonna set some session values, If one more user going to login using existing user logged in ID and password, before going to login condition, check those parameters in the back end. 因此,当用户登录时,您将设置一些会话值,如果还有一个用户使用现有用户登录ID和密码登录,则在进入登录状态之前,请检查后端的参数。 You can able to prevent user login from multiple times for the Same userLogin and Password. 您可以阻止用户多次登录Same userLogin和Password。

You can use either database or distributed cache. 您可以使用数据库或分布式缓存。

I prefer using database ( User_ID, SessionKey, LoginTime, Logout time) 我更喜欢使用数据库(User_ID,SessionKey,LoginTime,Logout time)

After login, you have to record entry in database/cache with a unique session id. 登录后,您必须使用唯一的会话ID记录数据库/缓存中的条目。 When login is attempted with same credentials, update existing entry with logout time and create new entry with recent login time 尝试使用相同凭据登录时,请使用注销时间更新现有条目,并使用最近登录时间创建新条目

eg When you login with John, 例如,当您使用John登录时,

the entry in table is like 'John','1020edf1','29-06-2015 00:10:00',null. 表中的条目类似于'John','1020edf1','29-06-2015 00:10:00',null。

When second login comes after 10 minutes, 第二次登录10分钟后,

The entries in table will be like this 表中的条目将是这样的

'John','1020edf1','29-06-2015 00:10:00','29-06-2015 00:20:00' 'John','10asdf21','29-06-2015 00:20:00','null' 'John','1020edf1','29-06-2015 00:10:00','29-06-2015 00:20:00''John','10asdf21','2015年6月29日00:20 :00' , '空'

Form your application, you can have reaper thread mechanism, which will remove inactive sessions if user tries to logout from the application. 构建您的应用程序,您可以使用reaper线程机制,如果用户尝试从应用程序注销,将删除非活动会话。

Here session key is unique session id generated by application server. 这里会话密钥是应用服务器生成的唯一会话ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM