<?php
declare(strict_types=1);

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

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

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

$email = mb_strtolower(trim($email));
$hash = password_hash($new, PASSWORD_BCRYPT);

$st = $db->prepare("UPDATE users SET password_hash = :hash WHERE LOWER(email)=:email");
$st->execute([':hash' => $hash, ':email' => $email]);

echo "Password updated for {$email}\n";
