Avoiding Same User Logging in Multiple Systems

Posted on 2006-11-28
Medium Priority
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 200 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.
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

LVL 10

Assisted Solution

ADSLMark earned 200 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 200 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 200 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 200 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

770 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