<?php
include '../config/conexion.php';
session_start();

if(isset($_POST['user_id'], $_POST['new_password'])){
    $user_id = $_POST['user_id'];
    $new_password = password_hash($_POST['new_password'], PASSWORD_DEFAULT);

    $database = new Connection();
    $conn = $database->open();

    $stmt = $conn->prepare("UPDATE usuarios SET pass = :pass WHERE id = :id");
    $stmt->bindParam(':pass', $new_password);
    $stmt->bindParam(':id', $user_id);

    if($stmt->execute()){
        $_SESSION['message'] = "Contraseña actualizada correctamente.";
    } else {
        $_SESSION['message'] = "Error al actualizar la contraseña.";
    }

    $database->close();
    header("Location: ../views/usuario");
    exit;
}
?>
