Connecting Tech Pros Worldwide Help | Site Map

prevent duplicate login

Newbie
 
Join Date: Jan 2007
Posts: 28
#1: Jul 1 '09
Dear All,

I would like to ask about login control. One of my I have to prevent the user duplicate login. I would like to know it is possible or not? If possible, could you tell me some logic for this.

Thanks all,
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#2: Jul 1 '09

re: prevent duplicate login


Quote:

Originally Posted by foekall View Post

Dear All,

I would like to ask about login control. One of my I have to prevent the user duplicate login. I would like to know it is possible or not? If possible, could you tell me some logic for this.

Thanks all,

Could you please explain the scenario a little more?
Newbie
 
Join Date: Jan 2007
Posts: 28
#3: Jul 1 '09

re: prevent duplicate login


Quote:

Originally Posted by Markus View Post

Could you please explain the scenario a little more?

My scenario is just simple. I am writing admin control for booking system. I create only one account for admin login but there are one or more user use this admin control with one account. I want to give permission to access admin control only one user at a time.

Thanks
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#4: Jul 1 '09

re: prevent duplicate login


Quote:

Originally Posted by foekall View Post

My scenario is just simple. I am writing admin control for booking system. I create only one account for admin login but there are one or more user use this admin control with one account. I want to give permission to access admin control only one user at a time.

Thanks

This is difficult because there is no reliable way to *know* when someone logs out. Sure, they may use a 'logout' facility on your application, but they may also -- and this is much more likely -- just close the browser, and, if they do, then you (the application) are left unaware.

There is a way to overcome this, although, again, it is not perfect nor precise.

When a user (admin) logs in, you update a flag (logged_in) in your database to true. You also log the datetime of the log in (see datetime - mysql). If a user decides to use the logout facility, update the database flag to reflect this.

Now onto the 'knowing when a user is logged out'.

Everytime your admin account performs an action (deletes record, creates record, etc), you update the datetime column to the current datetime. Now we have a general understanding of the admin accounts last activity.

When a user attempts to login as admin, you first check if there is someone already logged in (logged_in). If there is, you compare the last activity time to the current time. You then decide how long someone should have remained inactive before being flagged as logged out. If the last activity time is greater than the specified time, allow the person attempting to log in that priviledge.

Any questions?
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#5: Jul 1 '09

re: prevent duplicate login


Depending on your level of paranoia =), you could have a cron job that checks all the dates and logs all users off (let's say setting a logged_in field value to false) if the last activity time (like Markus) suggested is older than a specified period, like an hour.

Makes sense?



Dan
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#6: Jul 1 '09

re: prevent duplicate login


Quote:

Originally Posted by dlite922 View Post

Depending on your level of paranoia =), you could have a cron job that checks all the dates and logs all users off (let's say setting a logged_in field value to false) if the last activity time (like Markus) suggested is older than a specified period, like an hour.

Makes sense?



Dan

OMG! I was supposed to suggest that but completely forgot.

:D
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#7: Jul 1 '09

re: prevent duplicate login


Quote:

Originally Posted by Markus View Post

OMG! I was supposed to suggest that but completely forgot.

:D

Just admit it!, you can't be as good as me!! :P

BOW before the master!!

/jk




Dan
Newbie
 
Join Date: Jan 2007
Posts: 28
#8: Jul 2 '09

re: prevent duplicate login


Dear all,

Thanks for yours advice. I will try with datetime according to yours advice. If I have any question, I would like to ask again. :)

Thanks
foekall
Reply