diff --git a/tool_common.py b/tool_common.py index 80c7b69..c74c8cd 100644 --- a/tool_common.py +++ b/tool_common.py @@ -4,6 +4,8 @@ import json import traceback import base64 import hashlib +import random +import string # Constants @@ -76,3 +78,7 @@ def base64_to_json(content): def get_sha256(content): return hashlib.sha256(content.encode('utf-8')).hexdigest() + + +def get_randpass(length): + return ''.join(random.choices(string.ascii_uppercase, k=2) + random.choices(string.ascii_lowercase + string.ascii_uppercase + string.digits, k=length - 2)) diff --git a/tool_create.py b/tool_create.py index 29f1c94..d030b3a 100644 --- a/tool_create.py +++ b/tool_create.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import os import getpass -from tool_common import load_config, save_config, json_to_base64, get_sha256 +from tool_common import load_config, save_config, json_to_base64, get_sha256, get_randpass from tool_common import WGOP_LB_PBEGIN, WGOP_UC_PBEGIN, WGOP_USPEEDER_C_PBEGIN, WGOP_USPEEDER_S_PBEGIN @@ -105,10 +105,11 @@ if op_mode in ("s", "m"): break while True: - udp_server_password = getpass.getpass('Tunnel Password: ').strip() + udp_server_password = getpass.getpass('Tunnel Password: (Keep empty to generate one)').strip() if not udp_server_password: - print("For security reasons, a udp2raw tunnel password is required. Try again.") - continue + udp_server_password = get_randpass(15) + print("Generated Password: {}".format(udp_server_password)) + break if udp_server_password != getpass.getpass('Confirm Tunnel Password: ').strip(): print("Password mismatch. Try again.")