I have a website which clients can log in to. Their username, encrypted password and some additional info is stored in an SQL database on the server. I am setting up a cookie to remenber the user for some days.
I read everywhere I should not save the username and password in the cookie for security reasons. I have to say I am not sure to see why. The cookie is stored on client side right? Thus it is his username and password he is able to see, what is unsafe in that?
Anyway I pretty sure there are good reasons and it is just I cannot see it, I read the solution is to do that:
- hash and encrypt the password
- store the login information to a file on the server
- give the file a unique name
- store the name to a cookie
- each time you receive the cookie with the correct file name, look up the file and retrieve the login information.
So I should generate a unique ID to store in my database and associate it with the user.
How can I achieve that?