Avoiding Same User Logging in Multiple Systems

Posted on 2006-11-28
Last Modified: 2010-03-31
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
Question by:CIPL-Senthil
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 35

Expert Comment

ID: 18027315
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.

Author Comment

ID: 18027379
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
LVL 35

Accepted Solution

girionis earned 50 total points
ID: 18027457
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.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 10

Assisted Solution

ADSLMark earned 50 total points
ID: 18027471
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.
LVL 12

Assisted Solution

enachemc earned 50 total points
ID: 18027724
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.
LVL 35

Expert Comment

ID: 18028398
I think the issue is for the user *not to be* prompted for a second login if he is already logged in.

Assisted Solution

SamsonChung earned 50 total points
ID: 18029245
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.


Assisted Solution

harshgrover earned 50 total points
ID: 18031253
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.
LVL 12

Expert Comment

ID: 18032152
yes, make a DB query as oposed to keeping a hashmap. you make the calculations, and if you are in advantage .... make them again.

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question