0

In my application, I am not allowing the user to login more than once to the application with the same user. Every time he is login to the system I am updating his state in the database that he is logged in and after he logged out, his status is updated too. My question is that if there will be an error due to any reason and the application crashes, he will not be able to log in. My question is that is there any way where I can make the application detect if the user is idle for 15 minutes and activate his status. I am programming my application in c# and my database is MySQL database. Please suggest how can I do that. Thanks

user2103335
  • 63
  • 4
  • 13
  • Two suggestions: 1) you could create a login "expires" timestamp that is set to 15 minutes after initial login or any subsequent activity. If they try and login after the timestamp, let them. 2) you could clean up after a crash... when your app closes gracefully, set some flag in an .settings file in %appdata% (or somewhere). If the app starts up and sees that it didn't exit gracefully, let them login again... – Gojira Jun 21 '13 at 20:55

2 Answers2

0

You can store the time of last user request in the database, if it was longer than 15 min ago, he is idle.

alex
  • 12,464
  • 3
  • 46
  • 67
0

If you want a more robust solution which will allow immediate relogin, you can store the result of CONNECTION_ID() in your table. When the user logs out normally, set it back to NULL. If the connection ID is not NULL, you can use SHOW PROCESSLIST to determine if the connection is still present. If it is not, the application has crashed, and you can allow login. This depends, of course, on your application making just one persistent connection to the database.

Dark Falcon
  • 43,592
  • 5
  • 83
  • 98