<?php
require_once('session.php');
    $pass = $u['pass'];
    $password = password_hash($_POST['pass'],PASSWORD_DEFAULT);
    $repass = mysqli_real_escape_string($conn,$_POST['repass']);
    $old_pass = mysqli_real_escape_string($conn,$_POST['old_pass']);

    if (password_verify($old_pass, $pass)) {
    if (password_verify($repass, $password)) {
        $stmt = $conn->prepare("UPDATE `tb_user` SET `pass` = ? WHERE cuid = ?");
        $stmt->bind_param("si", $password, $userID); // Menggunakan variabel $password yang benar
        if ($stmt->execute()) {
            $_SESSION['notif'] = ['type' => 'success', 'message' => 'Password berhasil diubah!'];
            header('Location: ' . $_SERVER['HTTP_REFERER']);
            exit();
        } else {
            $_SESSION['notif'] = ['type' => 'danger', 'message' => 'Terjadi kesalahan saat mengubah password. Silakan coba lagi.'];
            header('Location: ' . $_SERVER['HTTP_REFERER']);
            exit();
        }
        $stmt->close();
    } else {
        $_SESSION['notif'] = ['type' => 'warning', 'message' => 'Konfirmasi password tidak cocok!'];
        header('Location: ' . $_SERVER['HTTP_REFERER']);
    exit();
    }
} else {
    $_SESSION['notif'] = ['type' => 'warning', 'message' => 'Password lama salah!'];
    header('Location: ' . $_SERVER['HTTP_REFERER']);
    exit();
}

header('Location: ' . $_SERVER['HTTP_REFERER']);
exit();

    
?>