fix(core): allow underscores in usernames
This commit is contained in:
@ -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.")
|
print("Invalid date. Please provide a valid date in YYYY-MM-DD format.")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if not re.match(r"^[a-zA-Z0-9]+$", username):
|
if not re.match(r"^[a-zA-Z0-9_]+$", username):
|
||||||
print("Error: Username can only contain letters and numbers.")
|
print("Error: Username can only contain letters, numbers, and underscores.")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if not os.path.isfile(USERS_FILE):
|
if not os.path.isfile(USERS_FILE):
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import argparse
|
import argparse
|
||||||
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from init_paths import *
|
from init_paths import *
|
||||||
from 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 = f"{prefix}{start_number + i}"
|
||||||
username_lower = username.lower()
|
username_lower = username.lower()
|
||||||
|
|
||||||
if not username_lower.isalnum():
|
if not re.match(r"^[a-zA-Z0-9_]+$", username_lower):
|
||||||
print(f"Error: Generated username '{username}' contains invalid characters. Please use an alphanumeric prefix.")
|
print(f"Error: Generated username '{username}' contains invalid characters. Use only letters, numbers, and underscores.")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if username_lower in existing_users_lower or username_lower in new_users_to_add:
|
if username_lower in existing_users_lower or username_lower in new_users_to_add:
|
||||||
|
|||||||
Reference in New Issue
Block a user