Avoiding Same User Logging in Multiple Systems

Hi Experts,

I have built a web application using J2EE. I would like to avoid same user logging in multiple systems.

Please advice.

Vijay T. Prabakar
Who is Participating?

Improve company productivity with a Business Account.Sign Up

girionisConnect With a Mentor Commented:
Is the login in the two machines happening from the same browser in the same computer? If yes then you can control it by either checking the session or the cookies. If not, then there is no way to do it.
Is your application deployed within a cluster? If yes then the session should be replicated across the cluster and you shouldn't need to do anything in order to assure the user won't login twice.

If not the best way is to always send a cookie with the user request. In this cookie you should have information about the user, for example something like login=true. Then upon each request check this cookie. If the login is true then the user is logged in, if not show the login page.
CIPL-SenthilAuthor Commented:
Hi girionis,

Say, a user with login name 'abc' and password 'abc' logs in machine1 and without logging out of machine1 the same user logs in machine2 with same login name and password ie., 'abc' and 'abc'.

How can I avoid this?

Please advice.

Vijay T. Prabakar
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

ADSLMarkConnect With a Mentor Commented:
You can use a session key. If the user logins into the system, you create a session key and store it in the database at the user's record.

For example:
username: abc
password: <hashed password>
sessionkey: <some hash key>

Next if the user communicates with the system, the application should sent along the session key and you should check the session key on the server. If the key does not equal the key stored with that persons username, then he is not logged on the system anymore. If the user tries to login from another machine2, then the sessionkey will change so the previous situation will occur for the user at machine1.

Using session keys also improves security, since you do not need to sent over the user+password every time (which is a bit risky since if the password (even an hashed password) is intercepted, then a evil person can brute force this password and always use it to logon the system), brute forcing a session key is useless and session keys only last for one session. You can even make it more secure to renew the session key every x minuts.

Good luck.
enachemcConnect With a Mentor Commented:
keep all your sessions in a weak hash map, and if a users makes a second log on, retrieve the previous session from the map and invalidate it.
I think the issue is for the user *not to be* prompted for a second login if he is already logged in.
SamsonChungConnect With a Mentor Commented:
that depends on the actual implementation.

I once wrote a program that goes to a generic user Table.

and fill a column of 'logged_in_session' +1, and another column called 'TotalAllowed'

Now, my codes would simply validate to see if logged_in_session >= TotalAllowed.

if that is false, continue with login.

else error message.

harshgroverConnect With a Mentor Commented:
i would agree with SamsonChung's idea...another implementation could also have a boolean field in the table which stores the User info. Everytime the user signs on, the boolean field could be set to true. and if the field is true, you could prompt an error message to the user indicating that he is already signed on. this would not cause any performance degrade too, since you would just be retrieving another field from the same user record in the database.
yes, make a DB query as oposed to keeping a hashmap. you make the calculations, and if you are in advantage .... make them again.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.