Question advanced login feature question

Mrt

Member
Joined
May 18, 2010
Messages
16
Programming Experience
1-3
Hello,

I am looking for some clues how to maintain login and logout opperations.

I using VB.Net and SQL SSMS 2008 Express Editions

I have implemented the login which is simple, once a user logs in a field in the database turns as 1 which means online.

Now my question is
If the user cuts the process using the end process feature of windows there is no way application could log him out, so the user would stay online for all the time which I am afraid off.

How do I log them users out?

Thank you
 
Use a class object

Personally I would create a Class Object for Login

Keep it off of the database.

Class default login = 0
That way if the user or computer kills unexpectedly. It would default back to 0

IMHO
 
You need to make it work basically like a web site. When the user logs in an expiry time is set on the session. Each time the user performs an action within that time, the expiry time is extended. If the attempts an action after the expiry time then it is rejected and they must login again.
 
I think the timer has to run in the database, I can't do this in the application because after it gets cut it is not going to send any signal to the database so it is not able to set the user as offline if it gets cut !

Can't get over this, I need to find a way to do this using a database because the application works online only
 
There is no actual timer. You simply store the date and time of the last action in the database. Each time an action is performed, you test the current time against the time of the last action. If it's past the session expiry period then you force a login, otherwise you perform the action and update the last action time.
 
Thanks for explaining,
as far as I understand using what you've suggested I could get 'how long has the user been online'.

but what I need is to have a field in the database which would identify if the user at the moment is:

1 (online)
0 (offline)

and the problem I see is if the app gets cut it will not set the user as 0 (offline) (so it would stay as 1 for until next time he logs in and maybe properly shuts down the application...



in other words if the application gets cut it stays as 1 (online)

If it's past the session expiry period then you force a login


what I understood from your previous post I could actually know when was the user online and how long was he online, but I am still short of knowing when did he cut the process :)

please correct me if I am wrong
 
What you're asking for is simply not possible. If the app doesn;t tell you that it is disconnecting then you simply can;t know that it's disconnected. As I said, this will have to work like a web site. When a user logs in, a session is created. That session is considered to be active as long as the user keeps making requests within a specific time period. As soon as that time period passes with no request, the session is considered closed.
 
OK, thanks, I got it

So the way I check if the user is online is:

Check the latest session stored in the database and if the current time is for example 30 min old I will take that as the user being offline

what about the users that are from other countries? due to the time differences...

how should I use one time for everybody on the application?

correct me If I am wrong but I think if I use function Now() in the application, it returns the time of user's windows time?
 
Time generated by client is of course client time, but there exist something known as Coordinated Universal Time (UTC), which you can easily get from a Date object. DateTime Structure (System)
If you execute a Sql time function then it is the server time that is used, this may also be a UTC value. Date and Time Functions (Transact-SQL)
UTC is usually the most convenient when you need to coordinate time between different time zones.
 
So I just have to use SQL Time which is fine.

I usually use CURRENT_TIMESTAMP expression to get the time which should work out fine

Thanks for all the info, I ll get back to the application now :)
 
Back
Top