OK the first thing that occurs to me is that both [man]crypt[/man] and [man]password_hash[/man] both have a mode where they use some unspecified "default" algorithm to hash passwords -- and there are no guarantees that this so-called "default" hash will remain the same. In fact:
The default algorithm to use for hashing if no algorithm is provided. This may change in newer PHP releases when newer, stronger hashing algorithms are supported.
Given that these are one-way hash functions, doesn't this seem like an absolutely terrible idea? I'm imagining updating my version of PHP to the latest only to find that my database with over a million hashed passwords are useless because they went and changed the "default" hash algorithm on me.
traq, thanks for that link. I believe I like how they have standardized the hashing thing with a very clear name. So very much in the philosophy of PHP to shield us dummies from the particulars. It sounds to me like it's probably just an alias to the crypt function which I had been asking about.
Weedpacket, I understand that one should check whether CRYPT_BLOWFISH==1 to see if it's available. It's the badly-named and abused $salt parameter that rankles me first. It's not really just a salt if you are also specifying the hash algorithm now is it? Seems like they could have added one more parameter for $algorithm rather than abusing $salt.
Secondly, the docs are not exactly clear. Is anyone else confused by this?
Blowfish hashing with a salt as follows: "$2a$", "$2x$" or "$2y$", a two digit cost parameter, "$", and 22 characters from the alphabet "./0-9A-Za-z". Using characters outside of this range in the salt will cause crypt() to return a zero-length string. The two digit cost parameter is the base-2 logarithm of the iteration count for the underlying Blowfish-based hashing algorithmeter and must be in range 04-31, values outside this range will cause crypt() to fail. Versions of PHP before 5.3.7 only support "$2a$" as the salt prefix: PHP 5.3.7 introduced the new prefixes to fix a security weakness in the Blowfish implementation. Please refer to ยป this document for full details of the security fix, but to summarise, developers targeting only PHP 5.3.7 and later should use "$2y$" in preference to "$2a$".
I'm confused in a variety of ways:
What's the damn difference between "$2a$", "$2x$" and "$2y$" ? What, exactly are we specifying here? I believe I understand that prefixing my salt with one of these values will tell crypt() to use blowfish as hashing algorithm but don't understand what each means?
"base-2 logarithm of the iteration count for the underlying Blowfish-based hashing algorithmeter and must be in range 04-31" -- LOLWUT? Do we just pick one? Is there any additional information about what they mean and the possible implications of choosing one over the oether?
Does the alphabet include periods and slashes or is something escaped there? Looks base-64ish but with a period instead of a plus, which is kind of odd.
am I correct in understanding that the example uses "usesomesillystringforsalt" as a salt (which is 25 chars instead of the specified 22 chars) and that the crypt algorithm just truncated the salt?
Having looked at the examples more, I think I now see that the resulting hash string includes both a specifier for the algorithm used and also the salt used. I guess this answers my first concern, right?