2 ms·
Upon login, one-way hash their password plus a fixed random string (NOT the same one as used to authenticate that they are logged in!). Then store that in a coo
by ars 6y ago
Upon login, one-way hash their password plus a fixed random string (NOT the same one as used to authenticate that they are logged in!). Then store that in a cookie.
When they post anonymously, store the value of that cookie in the database as-is (and don't validate it - you can't validate it anyway, you (hopefully) don't have their password). To edit a post, check that the value in the database matches the one in the cookie.
Remember: Unlike the authentication (session) cookie, this special cookie is never stored in a way that links it with their real user info.
This does not allow password changes, but that's probably OK since edits are usually done relatively soon after posting.
(If you really wanted to allow password changes, then every time they change passwords, update all of the matching hashes in the database to the new hash.)
A tip: Generate a list of harmless words (say you have 200 words).
When the user posts, one-way hash the value from the cookie, plus the topic (or thread) ID (whatever you use to group messages). And calculate the value of that hash mod 200, and call the user "Anonymous word4".
This way if the users posts more than once in the same topic, you can see that it's the same person - this makes conversation a lot easier.
- bobthebuilders 6y agoYou'd need to hash the cookie again in the DB, else a DB breach would give someone the power to edit any anonymous post.