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 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))

View File

@ -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.")