【问题标题】:Phalcon php hash same password produces multiple resultPhalcon php哈希相同的密码产生多个结果
【发布时间】:2014-07-17 01:57:13
【问题描述】:

我使用此语句通过 Phalcon 对密码进行哈希处理:
$hashedPassword= $this->security->hash($password)

但是这个语句使用相同的密码返回不同的结果。

示例:
设置 $password=123 我得到具有以下值的 $hashedPassword:

$2a$08$T2Rf9IcQHTj7TpY.gsfGiexZ35/KK9kS3fLElxaw8LGXhjnE01f5K$2a$08$E2mjApECMbRKQFZodgLkEOpDLSV/tEjTe1HV3q2LLG9UINj9M9GBm$2a$08$aZmgsMmG2xRueVzP6tkx2ucWGPZMzUwIccXbLJnqoRwDsSnT4zc.q


这是我用来检查用户密码的代码,
请让我知道我错过了什么。

if ($this->request->isPost() == true)
{
    $email = $this->request->getPost ("email");
    $password = $this->request->getPost ("password");

    $conditions = "email = ?1 AND admin = ?2";
    $parameters = array(1 => $email, 2 => 1);

    $users = Users::findFirst(array(
        $conditions,
        "bind" => $parameters
    ));

    if($users)
    {
        $security = new Phalcon\Security();
        $checkHashValue = $security->checkHash($password, $user->password);
        if($checkHashValue)
        {
            $this->flash->success($users->fullname);
        }
        else
        {
            //Print debug information
            $hash = $security->hash($password);

            $checkHash = $security->checkHash($password, $hash);

            $this->flash->error("Password: ". $password. 
            "<br/>Hash: " . $hash . "<br/>Check Hash: " . $checkHash . 
            "<br/>Check HashValue: ". $checkHashValue);
        }
    }
    else
    {
        $this->flash->error($password);
    }
}

解决方案:我的变量“user”而不是“users”中有错字。

【问题讨论】:

    标签: php hash phalcon


    【解决方案1】:

    这就是它应该如何工作的。它每次都会创建一个随机散列。要检查密码,请使用security-&gt;checkPassword()

    【讨论】:

    • 我已经发布了我的代码。我使用了security->checkPassword()。请让我知道我错过了什么。谢谢。
    【解决方案2】:

    解决方案:我的变量“user”而不是“users”中有错字。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-19
      • 1970-01-01
      • 2017-11-15
      • 1970-01-01
      • 2015-05-12
      • 2020-02-28
      相关资源
      最近更新 更多