<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/auth/cek_login.php';
include $_SERVER['DOCUMENT_ROOT'] . '/assets/db/db.php';

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $pass_baru = $_POST['pass_baru'];
    $hashed = password_hash($pass_baru, PASSWORD_BCRYPT);
    
    // Ambil ID dari session (id user yang sedang login)
    $admin_id = $_SESSION['admin_id'];

    $query = "UPDATE users SET password = '$hashed' WHERE id = '$admin_id'";

    if ($conn->query($query)) {
        echo "<script>alert('Password Berhasil Diperbarui!'); window.location.href='../entry/admin.php';</script>";
    } else {
        echo "Gagal: " . $conn->error;
    }
}
?>