<?php
include_once("database.php");
$postData = file_get_contents("php://input");
$request = json_decode($postData);

if (isset($postData) && !empty($postData)) {

    $pwd = mysqli_real_escape_string($mysqli, trim($request->password));
    $username = mysqli_real_escape_string($mysqli, trim($request->username));
    $sql = "SELECT * FROM users where username='$username'";

    if ($result = mysqli_query($mysqli, $sql)) {
        while ($row = mysqli_fetch_assoc($result)) {
            if (password_verify($pwd, $row['password'])) {
                echo json_encode($row);
                exit;
            }
        }
    }

    http_response_code(404);
}
