I have a Windows App Project to which users can login with their userid and passwords. I want to make it so that when a user logs in, I will get the Login Time, and if the u
1.st: User logs in, store the timestamp somewhere (for example this unix timestamp '1294230230' says it's aproximately 5th January 2011, 12:24)
int sess_creation_time = now(); *lets say 'now()' function returns current unix timestamp
2.nd: when user tries to perform any action, catch the timestamp of this attempt.
int temp_time = now();
Now, simply compare these values with your desired auto logout limit.
// compare here
// a, temp_time - sess_creation_time => the difference, time of inactivity
// 60*30 -> 60 seconds * 30 -> 30 minutes
if( (temp_time - sess_creation_time) > (60*30) )
{
// time of inactivity is higher than allowed, logout here
logout();
}
else
{
// session is still valid, do not forget to update its creation time
sess_creation_time = now();
}
Do not forget, this is not written in C/C++ or C#, but the logic remains the same ;-)
Hope, this helps you a bit