Search code examples
phpphp-password-hash

PHP: 'salt' option to password_hash is deprecated


I'm using password hashing for a registration. I need to create a Salt manually and following is the code I have used:

$options = [
    'cost' => 11,
    'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM)
];
$password = password_hash(
    $this->input->post("confirm_password"),
    PASSWORD_BCRYPT,
    $options
);

When I run this code it gives me an error saying:

password_hash(): Use of the 'salt' option to password_hash is deprecated"

Any solution for this?


Solution

  • Yes, there's a solution - don't use the 'salt' option.

    You don't need to salt manually, PHP does that automatically for you.

    It's not an option to add salt, but to replace the would-be-generated one, and under no circumstances would you be able to provide a better salt - that's why it's deprecated.