<?php 
include "../config/connect.php";

try {
    // Ambil data user
    $stmt = $pdo->prepare("SELECT id, nama, password FROM user_akses");
    $stmt->execute();

    while ($data = $stmt->fetch(PDO::FETCH_ASSOC)) {
        echo $data['id'] . " " . $data['nama'] . " " . $data['password'] . "<br>";
        
        // Hash password
        $hashedPassword = password_hash($data['password'], PASSWORD_DEFAULT);

        // Update password yang sudah di-hash
        $updateStmt = $pdo->prepare("UPDATE user_akses SET password = :password WHERE id = :id");
        $updateStmt->bindParam(':password', $hashedPassword);
        $updateStmt->bindParam(':id', $data['id']);
        $updateStmt->execute();
    }
} catch (PDOException $e) {
    // Tangani kesalahan
    echo "Terjadi kesalahan: " . $e->getMessage();
}
?>
