<?php
require_once "../config/db.php";
require_once "../inc/auth_admin.php";

$id = $_GET['id'] ?? 0;

if(!$id){
    header("Location: penghuni.php");
    exit;
}

// generate password baru 6 digit
$new_password_plain = rand(100000,999999);
$new_password_hash = password_hash($new_password_plain, PASSWORD_DEFAULT);

$stmt = $conn->prepare("UPDATE penghuni SET password=? WHERE id=?");
$stmt->bind_param("si", $new_password_hash, $id);
$stmt->execute();

// redirect dengan info password baru
header("Location: penghuni.php?reset_success=1&pass=".$new_password_plain);
exit;