3

I want that suppose if a user is logged into my website from one location and at a same time user tries to login from another location/computer then it should display "user is logged in already" or should give some error.. I am not asking for code so please dont close this question. I have searched alot then only I am posting this as a question .
Somebody please give me some links or some ideas so that i can implement it in my project. I have made a website in JAVA STRUTS2.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • While a user logged in to your site store a flag value in DB like status column value 1. After a user logged out or any other cases like browser crashes, etc. update it means set status value 0. If any one is trying to logging in in the middle then check the status value. if it is already 1 then display a message like 'you are already logged in'. I didn't have that much knowledge in that. If it useful +1. – SatyaTNV Jul 09 '15 at 06:49
  • I suggest you to go with some out-of-the-box solution (eg. Spring Security if it does it)... if you have the need to do it by yourself, then take a look at [this answer](http://stackoverflow.com/a/30727762/1654265) , even if the question was a bit different (restrict the number of tabs opened by the same user concurrently), it may help. – Andrea Ligios Jul 09 '15 at 08:00
  • Okay @Satya sir and Andrea sir i will try and will let you know what i did finally :) – Sid_dabangg Jul 09 '15 at 18:00
  • Other wise maintain a collection variable with user logged in details. If any user trying to logging then check in the collection variable whether the variable contains same user name or not. If it contains then display a message. – SatyaTNV Jul 10 '15 at 05:11

1 Answers1

1

Spring security has this, take a look at http://docs.spring.io/spring-security/site/docs/3.1.x/reference/session-mgmt.html#concurrent-sessions

You can either use spring security (which means redoing all your auth stuff) or look at their classes for concurrency and implement something similar.

Taylor
  • 3,942
  • 2
  • 20
  • 33