I am developing a REST web API to communicate with the server. In the function below, I am getting the user's login credentials and return the responses after validation.
The problem is whenever, I login with the correct credentials, it is showing the message 'Invalid Login credentials'.
I am pretty sure that, the values are not checking the conditions or the conditions (I check the email and password fields are not empty and validate the email by FILTER_VALIDATE_EMAIL are wrong.
private function login(){
if($this->get_request_method() != "GET"){
$this->response('',406);
}
$email = $this->_request['email'];
$password = $this->_request['pwd'];
if(!empty($email) && !empty($password)){
if(filter_var($email, FILTER_VALIDATE_EMAIL)){
$sql = mysql_query("SELECT id FROM user_login WHERE user_email = '$email'
AND user_password = '".md5($password)."' LIMIT 1", $this->db);
if(mysql_num_rows($sql) > 0){
$result = mysql_fetch_array($sql,MYSQL_ASSOC);
# If success everythig is good send header as "OK" and user details
$this->response($this->json($result), 200);
}
else {
$message = array('is_data' => 0,
"message" => "Invalid Login details");
$this->response($this->json($message), 400);
}
}
}
# If invalid inputs "Bad Request" status message and reason
$message = array('code' => "RES3001",
"message" => "Please check the parameters you sent");
$this->response($this->json($message), 400);
}
It would be very helpful if someone can help me to overcome this issue.