<?php
session_start();
include('db_connect.php');

$username = $_POST['username'];
$password = $_POST['password'];

$stmt = $conn->prepare("SELECT id, username, password FROM users WHERE username = ?");
$stmt->bind_param("s", $username);
$stmt->execute();
$result = $stmt->get_result();

if($result->num_rows > 0){
    $row = $result->fetch_assoc();
    if(password_verify($password, $row['password'])){
        $_SESSION['login_id'] = $row['id'];
        $_SESSION['username'] = $row['username'];
        echo 1;
    } else {
        echo 0;
    }
} else {
    echo 0;
}
?>
