Ok, I have this php code:
$_you = $_GET['you'];
$_answer = $_GET['answer'];
$_pass = md5($_GET['pass']);
$sql = "select password from users where username='$_you'";
$query = mysqli_query($db_conx, $sql);
while ($row = mysqli_fetch_array($query)) {
$_oldpass = $row['password'];
}
if ($_pass !== $_oldpass) {
$_passresult = "not ok";
} else {
$_passresult = "ok";
}
$sql2 = "select answer from useroptions where username='$_you'";
$query2 = mysqli_query($db_conx, $sql2);
while ($row2 = mysqli_fetch_array($query2)) {
$_veranswer = $row2['answer'];
}
if ($_answer !== $_veranswer) {
$_answerresult = "not ok";
} else {
$_answerresult = "ok";
}
$_result = array("Password" =>$_passresult, "Answer" =>$_answerresult);
header("Content-Type: application/json");
echo json_encode($_result);
?>
And this piece (fragment) of jquery that calls the above php:
$.get("verifydp.php?u="+you+"&pass="+pass+"&answer="+answer, function(result) {
if (result.Password === "not ok" ) {
$('#requiredp').html('<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Password is not correct');
$('#cpassword').css("border", "solid 1px #f60");
$('#cpassword').focus();
$('#cpassword').val('');
return false;
} else {
$('#requiredp').html('');
$('#cpassword').css("border", "solid 1px #ccc");
}
if ( result.Answer === "not ok" ) {
$('#requireda').html('<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> This is not the correct answer.');
$('#answer').css("border", "solid 1px #f60");
$('#answer').focus();
$('#answer').val('');
return false;
} else {
$('#requireda').html('');
$('#answer').css("border", "solid 1px #ccc");
}
});
As you may have guessed it, this is a little password verification thingie that I made, it's not done yet, so don't mention the fact that it's not 100 per cent safe yet. Just wanted to ask your help in the following remarkable problem that I get with the interaction between these two pieces of code:
It's verifying correct or incorrect passwords and answers, however, when I enter the correct password, it slaps me back saying the password is not correct. The funny thing is however that when I run the php part on its own with the same data it tells me the password is correct. So the php feeds an "OK" to Ajax and Ajax somehow turns it into a "NOT OK", which then causes the according mayhem in the rest of the script actions. Anybody got any idea why this is happening? Any help is greatly appreciated as it's doing my head in :-/ If you need more information, just let me know.
Thanks a million!