<?php
/**
 * WIMAS - Password Hash Generator & Updater
 * Location: /reset_pw.php
 * Note: Delete this file after running it once!
 */
require_once __DIR__ . '/config/bootstrap.php';

// The new plain-text password you want to set
$plain_text_password = "admin"; 

// 1. Generate the secure Bcrypt Hash
$hashed_password = password_hash($plain_text_password, PASSWORD_BCRYPT);

// 2. Direct value execution - no binding to catch any syntax issues
// We update the 'admin' account with this new hash
$sql = "UPDATE TBL_USERS 
        SET PASSWORD = '$hashed_password' 
        WHERE USERNAME = 'admin'";

$result = $db->query($sql);

?>
<!DOCTYPE html>
<html>
<head>
    <title>Password Reset Utility</title>
    <style>
        body { font-family: Arial, sans-serif; padding: 40px; background: #f4f6f9; }
        .card { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0,0,0,0.1); max-width: 600px; }
        .success { color: #155724; background-color: #d4edda; padding: 10px; border-radius: 4px; border: 1px solid #c3e6cb; }
        code { background: #eee; padding: 2px 6px; border-radius: 4px; font-size: 14px; word-break: break-all; }
    </style>
</head>
<body>
    <div class="card">
        <h3>Security Update Complete</h3>
        
        <?php if ($result): ?>
            <div class="success">
                <strong>Success!</strong> The admin password has been updated in the database.
            </div>
            
            <p><strong>Username:</strong> admin</p>
            <p><strong>New Raw Password:</strong> <code><?php echo $plain_text_password; ?></code></p>
            <p><strong>Generated Hash Saved:</strong><br> <code><?php echo $hashed_password; ?></code></p>
            
            <hr>
            <a href="login.php" style="display:inline-block; padding:10px 15px; background:#007bff; color:white; text-decoration:none; border-radius:4px;">
                Go to Login Page
            </a>
            <p style="color:red; font-size:12px; margin-top:20px;">
                ⚠️ <strong>CRITICAL:</strong> Please delete this <code>reset_pw.php</code> file from your server immediately after logging in.
            </p>
        <?php else: ?>
            <p style="color:red;">Database update failed.</p>
        <?php endif; ?>
    </div>
</body>
</html>