<?php
declare(strict_types=1);

define('CLI_SCRIPT', true);
require __DIR__ . '/../../public/index.php';

$db = \App\Core\Database::getInstance();

$email = '';
$pass  = '';
foreach ($argv as $a) {
    if (str_starts_with($a, '--email=')) $email = substr($a, 8);
    if (str_starts_with($a, '--pass='))  $pass  = substr($a, 7);
}
if ($email === '' || $pass === '') {
    echo "Usage: php check_password_hash.php --email=user@x.com --pass='PASSWORD'\n";
    exit(1);
}

$email = mb_strtolower(trim($email));

$st = $db->prepare("SELECT id, email, password_hash FROM users WHERE LOWER(email)=:email LIMIT 1");
$st->execute([':email' => $email]);
$u = $st->fetch();
if (!$u) { echo "User not found\n"; exit(1); }

$hash = (string)$u['password_hash'];
echo "ID: {$u['id']}\n";
echo "Email: {$u['email']}\n";
echo "Hash prefix: " . substr($hash,0,12) . "\n";
echo "Verify: " . (password_verify($pass, $hash) ? "TRUE" : "FALSE") . "\n";
