<?php
// Include database connection
include "../config.php";

// Check if the phone number and new password are provided
if (isset($_POST['phone']) && isset($_POST['password'])) {
    $phone = mysqli_real_escape_string($conn, $_POST['phone']);
    $password = $_POST['password'];

    // Hash the new password before saving it
    $hashedPassword = password_hash($password, PASSWORD_DEFAULT);

    // Update the user's password
    $query = "UPDATE users SET password = '$hashedPassword' WHERE phone = '$phone'";
    $result = mysqli_query($conn, $query);

    if ($result) {
        echo json_encode(["success" => true, "message" => "Password reset successfully"]);
    } else {
        echo json_encode(["success" => false, "message" => "Failed to reset password"]);
    }
} else {
    echo json_encode(["success" => false, "message" => "Phone number and new password are required"]);
}
?>
