[英]Setting a salt for password_hash()
我正在用PHP为owncloud
创建大量用户导入脚本。 我从CSV文件读取用户,然后将其添加到owncloud database
。 我的密码有问题。 据我所知,owncloud使用password_hash()
与BCRYPT
。 我有passwordsalt
,但是我不确定如何在password_hash()
使用该盐。
有什么帮助吗?
像这样在选项数组中使用盐
password_hash("rasmuslerdorf", PASSWORD_BCRYPT, array("cost" => 7, "salt" => "thisisyoursalt"));
但是,使用自己的盐并不是一个好主意。 让password_hash()
为您的密码创建一个盐。 password_hash()
将为每个密码创建不同的盐。 它将增加您的密码安全强度。
如果哈希值是由password_hash()
或crypt()
,则盐值将包含在所得哈希值中。 要针对此哈希检查密码,可以使用函数password_verify() ,该函数自动提取salt和其他参数。
// Check if the hash of the entered login password, matches the stored hash.
// The salt and the cost factor will be extracted from $existingHashFromDb.
$isPasswordCorrect = password_verify($password, $existingHashFromDb);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.