From 2626b44312d8c0f6caeaa81ac577766b1d8ffaaa Mon Sep 17 00:00:00 2001 From: kouhe <563554545@qq.com> Date: Sat, 26 Mar 2022 12:21:29 +0800 Subject: [PATCH] first commit --- main.py | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..b5861e5 --- /dev/null +++ b/main.py @@ -0,0 +1,76 @@ +import os +import re + +username_and_password = {} +wrong_time = 0 +while True: + print("\nWelcome to system!") + # press 1 to login,2 to register + print("1.login\n2.register") + # scan a number from keyboards + input_number = input("Enter a number\n") + if input_number == "1": + input_username = input("Enter a username\n") + input_password = input("Enter a password\n") + # check if the username and password are in the dictionary + if input_username in username_and_password: + if input_password == username_and_password[input_username]: + print("Login successfully!") + exit() + else: + print("Wrong password!") + wrong_time += 1 + if wrong_time == 3: + print("Too many wrong password!") + exit() + else: + print("Wrong username!") + elif input_number == "2": + input_username = input("Enter a username\n") + input_password = input("Enter a password\n") + # check if the username is in the dictionary so it is duplicate + if input_username in username_and_password: + print("The username is duplicate!") + else: + error_message = False + sensitive_words = ["傻", "蠢", "笨", "呆", "愚"] + # check if the username contains sensitive words + for word in sensitive_words: + if word in input_username: + print("The username contains blacklist words!") + # replace \u50bb\u8822\u7b28\u5446\u611a in input_username with * + input_username = re.sub('\u50bb', "*", input_username) + input_username = re.sub('\u8822', "*", input_username) + input_username = re.sub('\u7b28', "*", input_username) + input_username = re.sub('\u5446', "*", input_username) + input_username = re.sub('\u611a', "*", input_username) + + print("The username is changed to:", input_username) + error_message = True + break + # check password length + if len(input_password) < 6: + print("The password is too short!") + error_message = True + # check if the password contain alphabet and number + if not re.search("[a-zA-Z]", input_password): + print("The password must contain alphabet!") + error_message = True + if not re.search("[0-9]", input_password): + print("The password must contain number!") + error_message = True + if error_message: + print("Register failed!") + else: + # add the username and password to the dictionary + username_and_password[input_username] = input_password + print("Register successfully!") + print("Auto login...") + exit() + + else: + print("Wrong number!") # if the input is not 1 or 2, it will print wrong number + os.system("pause") + os.system("cls") + # clear the screen +