2014-04-21 3 views
1

제출 된 암호와 데이터베이스에서 호출 된 암호를 비교하는 데 문제가 있습니다. 모두 동일한 출력과 동일하지만, if 문에 비교했을 때 그들은 분명히 동일하지 않습니다 서로if 문에서 PHP MD5가 작동하지 않습니다.

<?php 
    session_start(); 
include("../functions.php"); 
connect(); 

$userPinLogin = $_REQUEST['pinLogin']; 
$userEmailLogin = $_REQUEST['emailLogin']; 
$i = session_id(); 
$findPin = md5($userPinLogin); 


$checkUserDetails = mysql_query("SELECT * FROM agentLogins WHERE email = '$userEmailLogin' AND pin = '$findPin' ") 
or die(mysql_error()); 
while($checkUserDetailsResults = mysql_fetch_array($checkUserDetails)) 
{ 
    $testUserPin = $checkUserDetailsResults['pin']; 
    $userLinkId = $checkUserDetailsResults['linkId']; 
    $testUserEmail = $checkUserDetailsResults['email']; 
} 


if (empty($testUserPin)) 
{ 

header ("Location: http://www.propertyclouduk.co.uk/agentPortal/index.php?er=pass"); 

} 

if ($findPin == $testUserPin) 
{ 
    echo "all match"; 


} 

else 
{ 
    echo "none match"; 
} 


?> 

모두 findPin & testUserPin = ad0234829205b9033196ba818f7a872b 만에 문이 그렇지 않은 말을 거짓 온다 if 문 경기

+1

: 당신은 몇 (email,pin)는 해당 테이블의 고유 한 것이 확실한 경우 하나의 결과 만이 때문에

, 당신은 루프를 필요로하지 않는, 그래서 당신은 지금처럼 테스트 할 수 있습니다 var_dump ($ findPin, $ testUserPin);'출력을 게시 하시겠습니까? –

+0

이 2 차 점검을 할 필요가 없습니다. MySQL은 일치하는 경우에만 행을 리턴합니다. – cmorrissey

+0

출력은 다음과 같습니다. 문자열 (32) "ad0234829205b9033196ba818f7a872b"문자열 (33) "ad0234829205b9033196ba818f7a872b" – Mark

답변

2

당신이 균열 된 바와 같이, 암호 해시를 위해 MD5를 사용 BCRYPT

,691의 대신 훨씬 더 안전

사용을 bcrypt 사용하지 말아야합니다 등록 페이지

--- 로그인 페이지

$pass = "the users password"; 
$secure_pass = password_hash($pass, PASSWORD_BCRYPT);;//the secured hashed pass 

----

$pass_by_user="the password entered by the user in the login page"; 
$pass_in_db= "the users password retrieved from the mysql table using the email or other non sensitive data"; 
$correct_pass= password_verify($pass_by_user, $pass_in_db);//comparison of the password in the database and the entered password 
+3

물론 사실이며 좋은 조언이지만 질문에 대한 답변이 아니기 때문에 댓글이되어야합니다. – Jason

+0

하지만 초보자가 오래된 라이브러리를 배우고 보안 수준을 낮추는데 많은 노력을 기울이는 것은 슬픈 일입니다. 그것은 진흙을 요리하기 위해 하루 종일 부엌에서 보내는 것과 같습니다. –

+0

@ ÁlvaroG.Vicario 그래 사실 그 조금 성가신하고 또한 슬픈 사실 –

0

나는 문제가 루프 전까지 checkUserDetailsResultsnull이다 간다 생각합니다.

그 시점에서 귀하의 수표는 분명히 실패합니다. `당신이 할 수

$result = mysql_query("SELECT * FROM agentLogins WHERE email = '$userEmailLogin' AND pin = '$findPin' ") 
or die(mysql_error()); 
$row = mysql_fetch_array($result); 
// mysql_fetch_array will return null if no row is found 
if($row){ 
    // We got a match, the check here will succeed 
    $testUserPin = $row['pin']; 
    $userLinkId = $row['linkId']; 
    $testUserEmail = $row['email']; 

    if ($findPin == $testUserPin){ 
    echo "all match"; 
    }else{ 
    echo "none match"; 
    } 
}else{ 
    // No match found, redirect 
    header ("Location: http://www.propertyclouduk.co.uk/agentPortal/index.php?er=pass"); 
    die; 
} 
관련 문제