0

使用时

    $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
4

1 回答 1

1

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

于 2012-06-22T04:37:38.933 回答