Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So you want a "Remember me on this computer" option? Here's a language-agnostic way how you can do it:</p> <ol> <li>Create a DB table with at least <code>cookie_id</code> and <code>user_id</code> columns. If necessary also add a <code>cookie_ttl</code> and <code>ip_lock</code>. The column names speaks for itself I guess.</li> <li>On first-time login (if necessary only with the "Remember me" option checked), generate a long, unique, hard-to-guess key which represents the <code>cookie_id</code> and store this in the DB along with the <code>user_id</code>. Also store this as cookie value of a cookie with a before specified cookie name. E.g. <code>remember</code>. Give the cookie a long lifetime, e.g. one year.</li> <li>On every request, check if the user is logged in. If not, then check the cookie value <code>cookie_id</code> associated with the cookie name <code>remember</code>. If it is there and it is valid according the DB, then automagically login the user associated with the <code>user_id</code> and postpone the cookie age again.</li> </ol> <p>As to the security risks, if the key is long and mixed enough (at least 30 mixed chars), then the chances on brute-forcing the login are negligible. Further on you probably already understood what the optional column <code>ip_lock</code> is to be used for. It should represent the IP address of the user. You could eventually add an extra checkbox "Lock login to this IP (only if you have a static IP)" so that the server can use the user's IP address as an extra validation. </p> <p>And what if one hijacked the cookie value from an user without an IP lock? Well, there's not much to do against this. Live with it. The "remember me" thing is funny for under each forums and account-hijacks wouldn't hurt that much there, but I would certainly not use it for admin panels and that kind of webpages which controls the server-side stuff.</p> <p>It's after all fairly straight forward. Good luck.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload