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 and user_id Create a DB table together Add cookie_ttl and ip_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 code user_id . Store cookie_id as a cookie value with the cookie name known as, e.g. Remember. Give the cookie a long life, e.g. one year.

  • On each request, check whether the user is logged in or not. If not, check the cookie value cookie_id associated with the cookie name . If it is there and it is legitimate according to DB, then the user is connected to user_id and automatically suspend the cookie age and if any, in the DB cookie_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.

Also see:


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -