MD5() and SHA-1 PHP replacement?

Hi,
Is there any PHP function that could be recommended to replace md5 and sha-1?
Currenltly I use,

$password = md5($_POST['password'] . '******');

Is it simply a case of replacing this with password_hash,

$options = [
    'cost' => 11,
    'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM),
];
$password = password_hash($_POST['password'], PASSWORD_BCRYPT, $options)."\n";

I am reading this from the PHP manual page
http://php.net/manual/en/function.password-hash.php

Thanks,
Shane

Hi,
The above isnā€™t working. I tried something a little simpler but still no output. This is in the body of a html file,

<?php
echo password_hash("rasmuslerdorf", PASSWORD_DEFAULT)."\n";
?>

The PHP manual says that there are no libraries or extra installation needed to use this function.
PHP version is 5.4.34

Thanks,
Shane

Yup. Except donā€™t create your own salt. The new password_hash function will do that for you. Also, Iā€™d suggest not specifying the algorithm either. One day, something better than bcrypt might come along and become the new default. When that happens, if you didnt specify bcrypt, then you get the new algorithm for free.

This function was introduced in PHP version 5.5. If youā€™re on less than that, then check out the ā€œuserland implementationā€ in the ā€œsee alsoā€ section.

1 Like

Ah yes, I see now that my hosting company is not using php 5.
Thanks,
Shane

Hi,
I canā€™t see ā€˜see alsoā€™ anywhere and what is meant by a ā€˜userland implementationā€™?
http://php.net/manual/en/function.password-hash.php
Shane

Sorry found it thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.