2014-07-16 37 views
0

我用这个语句哈希与尔康密码:
$ hashedPassword = $这个 - >安全 - >哈希($密码)尔康PHP哈希相同的密码生成多个结果

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

实施例:
设置$密码= 我得到$ 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); 
    } 
} 

SOLUTION:我有我的变量 “用户” 一个错字,而不是 “用户”。

回答

1

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

+0

我已经发布了我的代码。我使用安全 - > checkPassword()。请让我知道我错过了什么。谢谢。 –

0

解决方案:我在我的变量“用户”,而不是“用户”中有一个错字。