crypt()
will return a hashed string using the standard Unix DES-based algorithm if it's available on the system and if not then it will return MD5-based algoritm.
And you can set what type of algorithm you want to use from the following list:
- CRYPT_STD_DES .
- CRYPT_EXT_DES .
- CRYPT_MD5.
- CRYPT_BLOWFISH.
- CRYPT_SHA256.
- CRYPT_SHA512.
and this list can be used like this:
//setting the value to 1 means enable this algorithm
//which will return true or false.
if (CRYPT_STD_DES == 1) {
echo 'Standard DES: ' . crypt('rasmuslerdorf', 'rl') . "\n";
}
if (CRYPT_EXT_DES == 1) {
echo 'Extended DES: ' . crypt('rasmuslerdorf', '_J9..rasm') . "\n";
}
if (CRYPT_MD5 == 1) {
echo 'MD5: ' . crypt('rasmuslerdorf', '$1$rasmusle$') . "\n";
}
if (CRYPT_BLOWFISH == 1) {
echo 'Blowfish: ' . crypt('rasmuslerdorf', '$2a$07$usesomesillystringforsalt$') . "\n";
}
if (CRYPT_SHA256 == 1) {
echo 'SHA-256: ' . crypt('rasmuslerdorf', '$5$rounds=5000$usesomesillystringforsalt$') . "\n";
}
if (CRYPT_SHA512 == 1) {
echo 'SHA-512: ' . crypt('rasmuslerdorf', '$6$rounds=5000$usesomesillystringforsalt$') . "\n";
}
Which means that you have to choose what type of algorithm you want to use before using if you don't want to use the default by system.