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
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.
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

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

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

Suggested Solutions

Title # Comments Views Activity
session migration servlets 2 42
egit plugin on eclipse 8 82
How to convert from xls to xlsx using java 7 55
Cisco ASA: Java web start no go, asdm launcher no go 3 34
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

839 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