Created
October 17, 2017 12:39
-
-
Save wangerekaharun/30fc8241b4c6a8600640895662fc4078 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'db.php'; | |
// json response array | |
$response = array("error" => FALSE); | |
if (isset($_POST['email']) && isset($_POST['password'])) { | |
// receiving the post paramss | |
$email = $MySQLi_CON->real_escape_string(trim($_POST['email'])); | |
$upassword = $MySQLi_CON->real_escape_string(trim($_POST['password'])); | |
// get the user by email | |
$query = $MySQLi_CON->query("SELECT email, password FROM users WHERE email='$email'"); | |
$row=$query->fetch_array(); | |
if (password_verify($upassword, $row['password'])){ | |
echo json_encode($response); | |
} else { | |
// user is not found with the credentials | |
$response["error"] = TRUE; | |
$response["error_msg"] = "Login credentials are wrong. Please try again!"; | |
echo json_encode($response); | |
} | |
} else { | |
// required post params is missing | |
$response["error"] = TRUE; | |
$response["error_msg"] = "Required parameters email or password is missing!"; | |
echo json_encode($response); | |
} | |
$MySQLi_CON->close(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment