<?php
require_once __DIR__ . '/config/config.php';
require_once __DIR__ . '/config/database.php';

$db = Database::getInstance();

$users = [
    'admin'    => 'Admin@123',
    'customer' => 'Customer@123',
    'seller'   => 'Seller@123',
];

foreach ($users as $username => $plainPassword) {
    $hash = password_hash($plainPassword, PASSWORD_BCRYPT);
    $stmt = $db->prepare("UPDATE users SET password = :hash WHERE username = :username");
    $stmt->execute(['hash' => $hash, 'username' => $username]);
    
    // Verify immediately
    $check = $db->prepare("SELECT password FROM users WHERE username = :u");
    $check->execute(['u' => $username]);
    $stored = $check->fetchColumn();
    $ok = password_verify($plainPassword, $stored) ? 'OK' : 'FAIL';
    echo "[$ok] $username => " . substr($hash, 0, 30) . "...\n";
}

echo "\nAll done! Passwords updated successfully.\n";
