<?php
require "db.php";

$email = trim($_POST["email"] ?? "");
$password = $_POST["password"] ?? "";

$stmt = $pdo->prepare("SELECT * FROM users WHERE email = ? AND provider = 'email'");
$stmt->execute([$email]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$user || !password_verify($password, $user["password_hash"])) {
    die("Invalid login.");
}

$_SESSION["user_id"] = $user["id"];

header("Location: ../Index.php");
exit;