[article draft] Password hashing howto and hownotto

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Re: [article draft] Password hashing howto and hownotto

Postby allicient » Fri Sep 19, 2008 9:30 pm

As far as I'm aware there are two canonical ways of storing a hashed password (without consideration of any challenge-response authentication scheme... which is generally avoided in web apps because it implies use of Javascript crypto which isn't particularly good):

i) Store the pair Hash( salt || password ), salt in the database where the salt is unique for each password stored - this is an essential constraint (we're back to using /dev/urandom and probably concatenate with microtime as well). Using an additional constant salt is equivalent to a keyed hash, and is only useful if you can actually keep the key secret (which is unlikely if the webserver and database are on the same host). But in this instance I do tend to agree with you - its an easy way to get an additional layer of security, and have myself used this form in several implementations I've coded.

ii) Use something like PKCS#5 PBKDF2, again you'll be passing as an input "salt || password". This method (if the iteration count is high enough) makes it exeedingly difficult to mount an exhaustive search of the password space - even for relatively poor passwords.

Now, (ii) or similar is preferable and is used in products such as PGP (as far as I know) and PasswordSafe. Unfortunately, the (deliberate) time penatly may be too much for a webserver, and enforcing minimum password complexity with (i) may be more viable.


Note: I don't think (could be wrong, its been known to happen) there is *any* loss of entropy with applying the hash function multiple times (e.g. you're "double hashing", or PBKDF), although I would probably need to spend some time to do a proof and check. MD5, for example, pads its input with zeros to the 448th bit then appends a 64-bit value indicating the length to give a 512-bit input block. Given all the functions within MD5 are bijective, and that the only variable quantity in the repeated input is the 128-bit previous output (the rest are constant) - then H o H( x) should also be bijective, so H o H o .... o H( x ) is also bijective and hence no loss of entropy. Most MD-style hash functions also do not produce small cycles particularly easily, despite being poor on other fronts.


I liked that you'd written an article on this, it needs to be done. Even coders of very popular software can repeatedly get it wrong: http://www.lightbluetouchpaper.org/2008/04/25/wordpress-25-cookie-integrity-protection-vulnerability/
allicient
Forum Newbie
 
Posts: 9
Joined: Fri Sep 19, 2008 7:11 pm

Re: [article draft] Password hashing howto and hownotto

Postby califdon » Fri Sep 19, 2008 11:40 pm

I am woefully ignorant of this level of authentication security, but I learned a lot from reading your draft, Mordred, and add my thanks to that of others for your effort. About all I can contribute is a spelling correction: fashist -> fascist. And I must comment that, for a non-native English writer, you do remarkably well!
I think Heisenberg was probably right, but I can't be certain.
User avatar
califdon
Jack of Zircons
 
Posts: 3194
Joined: Thu Nov 09, 2006 9:30 pm
Location: California, USA

Re: [article draft] Password hashing howto and hownotto

Postby kaisellgren » Mon Sep 29, 2008 1:34 pm

Damn, you beat me at English :( - I'm also learning English, well, actually I'm just "trying" to.

Nice article you got there. I would add saucing to it, though.
Last edited by kaisellgren on Tue Sep 30, 2008 8:23 am, edited 1 time in total.
Kai
User avatar
kaisellgren
DevNet Resident
 
Posts: 1651
Joined: Sat Jan 07, 2006 6:52 am
Location: Lahti, Finland.

Re: [article draft] Password hashing howto and hownotto

Postby papa » Tue Sep 30, 2008 3:50 am

Very nice article! Exactly what I was looking for!
User avatar
papa
Forum Regular
 
Posts: 954
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: [article draft] Password hashing howto and hownotto

Postby The_Anomaly » Tue Sep 30, 2008 4:19 am

This article is pure awesome on so many levels. Best web security article I've ever read. Hopefully you'll find the time to write similar articles--whether it's on encryption, or just security in general.
The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music. - Donald Knuth
User avatar
The_Anomaly
Forum Contributor
 
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

Re: [article draft] Password hashing howto and hownotto

Postby Ijekic » Thu Oct 16, 2008 11:35 am

Yeah, extremely well written, thank you!
But since I'm a beginner, what I need is more how-to approach on how to implement the stuff. Fortunately, the article from Maugrim has all the details.

P.S.
I was amazed with your english fluency too!! Woow! Everytime I go to Sofia, I talk on some kind of Serbo-Bulgarian, because people usually don't know English well, but you.... 8O
Ijekic
Forum Newbie
 
Posts: 11
Joined: Sat Aug 16, 2008 11:36 am
Location: Belgrade, Serbia

Re: [article draft] Password hashing howto and hownotto

Postby Hannes2k » Fri Oct 24, 2008 1:11 pm

Hi,
what do you think about this class/script: Improved Hash Algorithm

It uses key strengthening for a more secure password hash so that the life for the bad guys would be realy unpleasent ;).
Hannes2k
Forum Contributor
 
Posts: 102
Joined: Fri Oct 24, 2008 12:22 pm

Previous

Return to PHP - Security

Who is online

Users browsing this forum: MSN [Bot] and 1 guest