<?php
require_once "auth.php";
$user = API_AUTH();

$new = $_POST['new_pass'] ?? "";

if(strlen($new) > 3){
    $hash = password_hash($new, PASSWORD_BCRYPT);

    $q = $conn->prepare("UPDATE users SET password=? WHERE id=?");
    $q->bind_param("si",$hash,$user['id']);
    $q->execute();

    echo "<script>alert('Password updated.'); window.location='../settings.php';</script>";
    exit;
}

echo "<script>alert('Nothing to update.'); window.location='../settings.php';</script>";
?>
