PHP,Openwall便携式PHP密码哈希框架为同一个单词返回不同的哈希值

时间:2012-06-22 04:10:58

标签: php passwords hash

使用时

    $t_hash = new PasswordHash(12, FALSE);

的每个实例
    $passHASH = $t_hash->HashPassword($password);
即使出现相同的单词,

也会返回不同的结果。例如:

$t_hash->HashPassword('test') => $2a$12$7OKS2iaFMWfTYL7sHdl9EunA90.ZdiEIXgPcpXFsqrhD3z7tk06eO
$t_hash->HashPassword('test') => $2a$12$MWtkeSMQgUU22nCjRZmV8uG8dgHByM1nvyrk7XE9bw6znK8ZDFfwy
$t_hash->HashPassword('test') => $2a$12$Dx1sYTWIZmiREyn0KYh4G.daUNsmksYiSpnUKdaHZMrELIwmlhPyW

任何人都可以帮我解决这个问题吗?执行以下代码时

$t_hash = new PasswordHash(12, FALSE);
$passwordHASH = $t_hash->HashPassword($array['pass']);
$passwordHASH = $t_hash->HashPassword($passwordHASH,$array['pass']);
print($passwordHASH."<br/>");
$passwordHASH = $t_hash->HashPassword($passwordHASH,$array['pass']);
print($passwordHASH."<br/>");
$passwordHASH = $t_hash->HashPassword($passwordHASH,$array['pass']);
print($passwordHASH."<br/>");
$passwordHASH = $t_hash->HashPassword($passwordHASH,$array['pass']);
print($passwordHASH);

返回

$2a$12$h3BLa3ytEmASpHgqVnmj4.3K5TwPPqwQG/cGHx/64KN1lqMtFZ8dC
$2a$12$x4uK46uBjv5xVstc4sR7iOrOJGPbSbWJRZIFlz9ir7ktydpYqStxO
$2a$12$r.CAy.amcVTFG.CtkTNg0eBN4HXP8tp4Yj/tsIVH7SxmK1bGjQJLS
$2a$12$8NzPVId7ReZVJJA7oWtkvuR2WKwPIUkpY/NQ2lszSH6EwdubzyIrm

1 个答案:

答案 0 :(得分:1)

这是正确的行为,HashPassword每次调用时都会使用随机盐,因此结果不一样。