<?php
include 'koneksi.php';

if (isset($_POST['reset'])) {
    $id_user = $_POST['id_user'];
    $password = $_POST['password'];

    if (strlen($password) < 6) {
        echo "<script>alert('Password minimal 6 karakter!'); window.location='pengguna.php';</script>";
    } else {
        // Hash password untuk keamanan (gunakan password_hash jika ingin lebih aman)
        // $hashed_password = password_hash($password, PASSWORD_DEFAULT);
        
        $query = "UPDATE users SET password = '$password' WHERE id_user = '$id_user'";
        
        if (mysqli_query($conn, $query)) {
            echo "<script>alert('Password berhasil direset!'); window.location='pengguna.php';</script>";
        } else {
            echo "<script>alert('Gagal mereset password.'); window.location='pengguna.php';</script>";
        }
    }
}
?>