Added Recaptcha
This commit is contained in:
+23
-26
@@ -24,48 +24,45 @@ $result = query_username($conn, $userName);
|
||||
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
|
||||
$row = $result->fetch_assoc();
|
||||
|
||||
$passWord_hashed = $row["C_Password"];
|
||||
$passWord_correct = password_verify($passWord_user, $passWord_hashed);
|
||||
if ($passWord_correct === false) {
|
||||
echo "<script> alert('Wrong password!');location.href='../index.html'; </script>";
|
||||
echo "<script> alert('Wrong password!');location.href='../index.php'; </script>";
|
||||
exit();
|
||||
} else {
|
||||
|
||||
// if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {
|
||||
if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {
|
||||
|
||||
// $secretKey = "6LehX_4aAAAAANIoyIRIYn8QzZtwtE7ytaQ1hgmZ";
|
||||
// $responseKey = $_POST['g-recaptcha-response'];
|
||||
// $userIP = $_SERVER['REMOTE_ADDR'];
|
||||
// $url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$userIP";
|
||||
// $response = file_get_contents($url);
|
||||
// $response = json_decode($response);
|
||||
$secretKey = "6LdDrc8bAAAAAGhP99aDPJ2_6O7yrwIUc8yJLaQU";
|
||||
$responseKey = $_POST['g-recaptcha-response'];
|
||||
$userIP = $_SERVER['REMOTE_ADDR'];
|
||||
$url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$userIP";
|
||||
$response = file_get_contents($url);
|
||||
$response = json_decode($response);
|
||||
|
||||
// if($response->success){
|
||||
// echo "Verification success.";
|
||||
// $_SESSION['username'] = $userName;
|
||||
// header("Location: shopping.php");
|
||||
// } else {
|
||||
// echo "<script> alert('reCAPTHCA verification failed, please try again.');location.href='login.php'; </script>";
|
||||
// return;
|
||||
// }
|
||||
if($response->success){
|
||||
echo "Verification success.";
|
||||
$_SESSION['username'] = $userName;
|
||||
header("Location: ../shopping/shopping.php");
|
||||
} else {
|
||||
echo "<script> alert('reCAPTHCA verification failed, please try again.');location.href='login.php'; </script>";
|
||||
return;
|
||||
}
|
||||
|
||||
// } else {
|
||||
// echo "<script> alert('Please click reCAPTHCA to verify.');location.href='login.php'; </script>";
|
||||
// return;
|
||||
// }
|
||||
} else {
|
||||
echo "<script> alert('Please click reCAPTHCA to verify.');location.href='../index.php'; </script>";
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: delete later
|
||||
echo "Verification success.";
|
||||
$_SESSION['username'] = $userName;
|
||||
header("Location: ../shopping/shopping.php");
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// echo "<script> alert('Username dosen't exist.Please sign up first.');location.href='../index.html'; </script>";
|
||||
header("Location: ../index.html");
|
||||
// echo "<script> alert('Username dosen't exist.Please sign up first.');location.href='../index.php'; </script>";
|
||||
header("Location: ../index.php");
|
||||
exit();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user