I am looking for an up to date method of keeping a user logged in with the famous 'Remember me' checkbox.
This is what I have got so far from combining other posts and tutorials:
User enters username and password. If valid - A Cookie is generated containing an Identifier and a Token. Both of these values are unguessable random numbers/characters.
The Identifier and Token are stored in a database with the user id.
When a non-logged-in user visits the website with a login Cookie, the Identifier is looked up in the database; if present, the Token is compared; if not, the Cookie is ignored and the user must login with his/her password.
If the Tokens match - the user is authenticated:
- The Cookie is destroyed.
- A new Cookie is issued with a different Identifier and Token.
- The Database is updated with the new Identifier and Token values against the user id.
Have I missed anything?