- Dec 1, 2000
- 2,419
- 0
- 0
So when a user logs in on my website, I give them a cookie
Username=TheirUserName
And I set it expiry date to a long time from now. I then use the cookie to determine whether or not the user is logged in.
I recently realized that this is actually a security flaw, because someone else could fake a cookie and log into any user's account so long as they knew the username.
This is my proposed solution, and I'd like to know if it makes sense:
I'll add a second hash value to the cookie:
Username=TheirUserName
Hash=17894728942abcd
And store the hash in the user database.
Now if someone tries to "fake" a login cookie, they'd have to guess the hash right.
Is this a good solution to this problem?
Username=TheirUserName
And I set it expiry date to a long time from now. I then use the cookie to determine whether or not the user is logged in.
I recently realized that this is actually a security flaw, because someone else could fake a cookie and log into any user's account so long as they knew the username.
This is my proposed solution, and I'd like to know if it makes sense:
I'll add a second hash value to the cookie:
Username=TheirUserName
Hash=17894728942abcd
And store the hash in the user database.
Now if someone tries to "fake" a login cookie, they'd have to guess the hash right.
Is this a good solution to this problem?