From 5a762ad918927274499020fa13dc77e41a646918 Mon Sep 17 00:00:00 2001 From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com> Date: Wed, 20 Aug 2025 23:45:01 +0330 Subject: [PATCH] fix(core): allow underscores in usernames --- core/scripts/hysteria2/add_user.py | 4 ++-- core/scripts/hysteria2/bulk_users.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/scripts/hysteria2/add_user.py b/core/scripts/hysteria2/add_user.py index 67a041e..ec23b0a 100644 --- a/core/scripts/hysteria2/add_user.py +++ b/core/scripts/hysteria2/add_user.py @@ -60,8 +60,8 @@ def add_user(username, traffic_gb, expiration_days, password=None, creation_date print("Invalid date. Please provide a valid date in YYYY-MM-DD format.") return 1 - if not re.match(r"^[a-zA-Z0-9]+$", username): - print("Error: Username can only contain letters and numbers.") + if not re.match(r"^[a-zA-Z0-9_]+$", username): + print("Error: Username can only contain letters, numbers, and underscores.") return 1 if not os.path.isfile(USERS_FILE): diff --git a/core/scripts/hysteria2/bulk_users.py b/core/scripts/hysteria2/bulk_users.py index e8fdca1..b1f4618 100644 --- a/core/scripts/hysteria2/bulk_users.py +++ b/core/scripts/hysteria2/bulk_users.py @@ -5,6 +5,7 @@ import sys import os import subprocess import argparse +import re from datetime import datetime from init_paths import * from paths import * @@ -51,8 +52,8 @@ def add_bulk_users(traffic_gb, expiration_days, count, prefix, start_number, unl username = f"{prefix}{start_number + i}" username_lower = username.lower() - if not username_lower.isalnum(): - print(f"Error: Generated username '{username}' contains invalid characters. Please use an alphanumeric prefix.") + if not re.match(r"^[a-zA-Z0-9_]+$", username_lower): + print(f"Error: Generated username '{username}' contains invalid characters. Use only letters, numbers, and underscores.") continue if username_lower in existing_users_lower or username_lower in new_users_to_add: