2017-02-27 27 views
0

hash_pbkdf2를 사용하는 해시 패스워드가있는 기존 테이블이 있습니다. 사용자 등록을 위해서는 mysql에 성공적으로 삽입하십시오.laravel 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

첫 번째 코드 블록에서 암호를 $ salt 대신 $ string 값으로 저장하고 데이터베이스에 $ salt를 저장합니다.

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

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

에 :

그래서 난 당신이 첫 번째 코드 블록에서 변경할 필요가 있다고 생각