Using crypt()
is fine, as long as you don't use the old DES-based mode (CRYPT_STD_DES
). The only valid reason to use that is for interoperability with legacy software that uses such password hashes.
Instead, use the CRYPT_BLOWFISH
, CRYPT_SHA256
or CRYPT_SHA512
modes. These are modern password hashing algorithms that accept arbitrarily long passphrases, use long salts and support key strengthening via multiple iterations.
Unfortunately, the PHP crypt()
interface is somewhat awkward: the only way to explicitly choose the algorithm you want is by supplying a correctly formatted $salt
parameter, which means you also have to generate the actual salt yourself. That's probably still easier and safer than rolling your own password hashing code, though.