java - How do I keep a user logged into my site for months? -
I am using OpenID How do I create it so that the user logs in for a long time after closing the browser window Are you doing
How can I store a user's user
object?
Actually, I think I really can not understand how the sessions work in Java.
So do you really like the "Remember me on this computer" option? This is actually unrelated to the OpenID part. Here's a language - you can do it in an unknowable way:
-
First, at least
cookie_id
anduser_id
Create a DB table together Addcookie_ttl
andip_lock
if necessary. The names of the columns speak for me I think -
On the first time login (if necessary with the "Remember me" option), Generate a long, unique, hard-guess The key (which is related to the user there is no way ) that shows
cookie_id
and it should be in codeuser_id
. Storecookie_id
as a cookie value with the cookie name known as, e.g. -
On each request, check whether the user is logged in or not. If not, check the cookie value
cookie_id
associated with the cookie nameuser_id
and automatically suspend the cookie age and if any, in the DBcookie_ttl
.
In Java / JSP / Charlotte words, add a cookie and use it to get cookies. You can check for the first time in a filter
, which listens to the desired records, e.g. / *
Or maybe a little more restricted.
Regarding the sessions, you do not need it here. It is a little too old to use the logged-in user or "found" user to use it to keep a valid memorize
cookie in the same way as the filter
Check the presence and then there is no need to check the cookies all the time.
All this is quite straight forward, after all the best wishes.
Comments
Post a Comment