2017-02-27 136 views
0

我有一个使用hash_pbkdf2哈希密码的现有表。对于用户注册,它的成功插入到MySQLlaravel php pbkdf2登录验证

$string = mcrypt_create_iv(24, MCRYPT_DEV_URANDOM); 
$salt = strtoupper(bin2hex($string)); 
$hash = hash_pbkdf2("sha1", $data['password'], $string, 1000, 24, true); 
$hash = strtoupper(bin2hex($hash)); 

return User::create([ 
    'name' => $data['name'], 
    'email' => $data['email'], 
    'hashedpassword' => $hash, 
    'salt' => $salt, 
]); 

我有麻烦登录和使用它。这里是我的代码

$found_salt = DB::table('users')->where('email', '[email protected]')->first(); 
$salt = $found_salt->salt; 

echo "Salt : ".$salt."<br>"; 
$hash = hash_pbkdf2("sha1", "password", $salt, 1000, 24, true); 
$hash = strtoupper(bin2hex($hash)); 

$userlogin = [ 
    'email' => "[email protected]", 
    'hashedpassword' => $hash 
]; 
echo "Hash : ".$hash."<br>"; 

if(Auth::attempt($userlogin)) { 
    echo "success"; 
} else { 
    echo "not success"; 
} 

盐值相同,但散列值不匹配。希望有人能帮助。谢谢。

回答

0

在您的第一个代码块中,您将使用$ string而不是$ salt的值为您的密码赋值,但将$ salt存储到数据库中。

所以我认为你需要在你的第一个代码块来改变这一点:

$hash = hash_pbkdf2("sha1", $data['password'], $string, 1000, 24, true);

$hash = hash_pbkdf2("sha1", $data['password'], $salt, 1000, 24, true);