On a website I am developing I am currently checking if a user is logged in if it’s cookies are set. The thing is I’m using these information for some request on the database and allow him to do some tasks on the website. Though, it came to my mind that if the user edit its cookies, he might be able to be someone else (editing it’s username/id). So, is there a way to secure it or do I have to use sessions ?
Share
Yes, you can use cookies. You just need to make sure that the cookie provides data you can use to authenticate the user, and not a token that means the user is authenticated.
Bad cookie:
Good cookie:
And then compare the authentication data against a datastore on the server.
Sessions are a way to store temporary about a user (who may or may not be authenticated). They are a quick and easy way to solve part of the problem and not something that should cause reactions of Do I have to? 🙁.
Most session libraries use cookies to store the token that links the collection of data associated with a session to the browser to which the session belongs.