关于 password_hash() 的问题

questions about password_hash()

我只是对 password_hash() 函数有一点疑问,它会为我创建随机盐吗?我的意思是我不必指定这样的内容:

'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM)  

因为我假设该函数为密码的 EACH 创建了一个 随机且不同的 盐?

另一个问题,如果我以这种方式在函数 password_hash 中使用 PASSWORD_DEFAULT : password_hash("rasmuslerdorf", PASSWORD_DEFAULT) 就像使用 password_hash("rasmuslerdorf", PASSWORD_BCRYPT) ?

盐是自动生成的,但您可以在选项中指定您自己的盐。 从 PHP 5.5 开始,默认算法是 BCRYPT,但它可以随时间变化。

根据文档,如果您没有指定任何盐,它每次都会生成一个随机盐:

salt - to manually provide a salt to use when hashing the password. Note that this will override and prevent a salt from being automatically generated.

If omitted, a random salt will be generated by password_hash() for each password hashed. This is the intended mode of operation.

http://php.net/manual/en/function.password-hash.php

password_hash()每次调用都会自动生成一个随机盐,除非你手动指定一个第三个参数,$options.

PASSWORD_DEFAULT等同于PASSWORD_BCRYPT 从 PHP 5.5 开始,但是将来可能会改变。 您不应该假设 PASSWORD_DEFAULT 将在 PHP.[=10= 的未来版本中始终使用 bcrypt 算法]

the very fine manual-

If omitted, a random salt will be generated by password_hash() for each password hashed. This is the intended mode of operation.

另外(你的第二个问题)更多来自 the very fine manual -

PASSWORD_DEFAULT (integer)

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.

...

Values for this constant:

PHP 5.5.0 - PASSWORD_BCRYPT