Random generate server password by default

This commit is contained in:
Kirigaya Kazuto 2021-08-22 17:27:36 +00:00
parent 1575472880
commit c65d9664a3
2 changed files with 11 additions and 4 deletions

View File

@ -4,6 +4,8 @@ import json
import traceback import traceback
import base64 import base64
import hashlib import hashlib
import random
import string
# Constants # Constants
@ -76,3 +78,7 @@ def base64_to_json(content):
def get_sha256(content): def get_sha256(content):
return hashlib.sha256(content.encode('utf-8')).hexdigest() 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))

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os import os
import getpass 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 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 break
while True: 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: if not udp_server_password:
print("For security reasons, a udp2raw tunnel password is required. Try again.") udp_server_password = get_randpass(15)
continue print("Generated Password: {}".format(udp_server_password))
break
if udp_server_password != getpass.getpass('Confirm Tunnel Password: ').strip(): if udp_server_password != getpass.getpass('Confirm Tunnel Password: ').strip():
print("Password mismatch. Try again.") print("Password mismatch. Try again.")