2012-09-04 1 views
0

나는 crypt와 blowfish를 사용하는 간단한 로그인 시스템을 사용합니다. 그러나, 내 인생에 대한 이유는 함수가 내 데이터베이스에 저장된 등록 된 암호를 생산하지 않는 알아낼 수 없습니다. 토굴 기능에 문제가 있습니까?암호 기능이 올바른 암호를 반환하지 않음

여기에 암호가 데이터베이스에 등록됩니다.

function unique_md5() { 

    mt_srand(microtime(true)*100000 + memory_get_usage(true)); 

    return md5(uniqid(mt_rand(), true)); 

} 

if ($password == $password_again) { 

$md5 = substr(unique_md5(), 0, 15); 

$string = '$2a$07$' . $md5; 

$password = trim($password); 

$protected_password = crypt($password, $string); 

//rest of code involved putting that $protected_password into database 

로그인 페이지 코드

$password = 'password'; 

echo '$2a$07$4cf0aa3a82e8d78$$$$$$.M4dWdC3N7OF.hphzfyswwszM7RFJUfu'; 

//the echo below echos out the exact same thing as the echo above, but the if statement 
//recognizes it as not equal to 

echo $registered_password = registered_password($mysqli, $username); 

if ($password == crypt($password, $registered_password)) 

    { 

    echo 'Working'; 

    } else { 

    echo 'Not working'; 

} 
+0

당신이 암호를 암호화하고 데이터베이스에 작성하는 코드를 보여줄 수 :

귀하의 비교는 무언가 같이해야 하는가? –

답변

1

당신은 잘못 crypt 기능을 사용하고 있습니다. 암호화 된 암호와 평문 암호가 아닌 crypt의 결과를 비교해야합니다.

if ($encrypted_password_from_database == crypt($user_provided_password, $encrypted_password_from_database)) { 
    // match 
} else { 
    // no match 
}