2 ms·
> You're not using SHA1, you're using keyed SHA1 with a secret random key. Does that mean that doing so is OK, except for the read any file breach? Because I'
by ars 17y ago
> You're not using SHA1, you're using keyed SHA1 with a secret random key.
Does that mean that doing so is OK, except for the read any file breach?
Because I've been doing that cookie authentications. Database and file reads are not something I'm worried about (for this situation), but I don't want the cookie to be easy to crack.
I.e. auth = sha1('long secret string' . 'user_id' . 'password') /* I include the password to invalidate existing cookies if someone changes their password */
I then set a cookie to the user_id, and another cookie to auth, and check them on every page.
Also, I'm not him, so I'd like to know why doing the config salt second instead of first is bad. I thought you could do a partial hash, i.e. hash the config salt once, then just keep updating it with the rest. Meaning, the config salt should go second, not first.
- tptacek 17y agoYou are sending a crackable password hash on every request. Stop doing that. Create a session table, key it off a 48-byte random string from /dev/random, and store authenticators in that. In other words, JSESSIONID or RACK.SESSION or PHPSESSIONID or ASPSESSIONID are all stronger approaches than the one you've chosen. You are going through extra effort to make your system less secure. If the config salt is the second term hashed, the scheme has a basic crypto flaw, one you can't make if you just use BCrypt or PBKDF like a reasonable developer instead of designing your own vanity scheme.
- heresy 17y agothanks. every time someone uses the password as input to some "secure" hash, i cry inside. why is the password even relevant to a user session identifier? it's not.
- ars 17y agoAnd the next time someone logs in as you, and clicks "keep me logged in" - and you have no way to un-log them in, you should also cry inside. If the password is changed, all session identifiers must be invalidated. If it's a session table, delete all entries, if it's a hash - well your hash had better include the password somehow (a hash of the password hash, i.e. the one stored in the db, is fine, as long as changing the password changes the final hash).
- heresy 17y agosession lifetime is an orthogonal concern to the password. i just don't see it as a good idea to have the password be one of the inputs to the value of the session identifier in any way, which was my point. you can handle every scenario you bring up without tying password to session id.