I am writing an API for a login page, where the password is encrypted and stored in the database as: "$2y$08$NwjkR19Vafs28PuSmVrd6OIpL2ix2hUZn4cFwwJqseUQJZqJIXpia". How do I verify this against the password entered by using an sql query , below is my API code:
if (isset($postdata)) {
    $request = json_decode($postdata);
    $username = $request->username;
    $password = $request->password;
    if( $username === NULL && $password === NULL) {
        $json = array("status" => 0, "message" => "Please enter username and password");
    }
    else {
        $select_sql = "SELECT `id`, `first_name`, `last_name`, `email`, `phone`, `username`, `password`, `created_on`, `active`, `activation_code` FROM `users` WHERE `email` = '".$username."' AND `password` = '".$password."';";
        $select_query = mysqli_query($con,$select_sql);
        $count = mysqli_num_rows($select_query);
        $fetch_obj = mysqli_fetch_array($select_query,MYSQLI_BOTH);
        if($count>0) {
            $userId = $fetch_obj["id"];
            $userEmail = $fetch_obj["email"];
            $userDisplayName = $fetch_obj["first_name"]." ".$fetch_obj["last_name"];
            $userPhone = $fetch_obj["phone"];
            $userName = $fetch_obj["username"];
            $userPass = $fetch_obj["password"];
            $userCreatedOn = $fetch_obj["created_on"];
            $userActive = $fetch_obj["active"];
            $userActivationCode = $fetch_obj["activation_code"];
            $userDetails = array( "UserID" => "$userId", "UserDisplayName" => "$userDisplayName", "UserEmail" => "$userEmail", "UserPhone" => "$userPhone", "UserName" => "$userName", "UserPassword" => "$userPass", "UserCreatedOn" => "$userCreatedOn","UserActive" => "$userActive", "UserActivationCode" => "$userActivationCode");
            $json = array("status" => 1, "message" => "Login success.", "UserDetails" => $userDetails);
        }
        else {
            $json = array("status" => 0, "message" => "Invalid username or password.", "query" => $select_sql );
        }
    }
}
mysqli_close($con);
I have tried using the below code but no matter what password I enter here it shows as Valid password,
 <?php
  echo $password = "John@798";
  echo $hash =  password_hash($password, PASSWORD_BCRYPT);
  if (password_verify($password, $hash)) {
  echo 'Password is valid!';
  } else {
  echo 'Invalid password.';
  }
  ?>
Is there any way I can check the password entered and then redirect the user to the homepage? Please help me, am stuck with this since past 2 days. Thanks in advance
 
    