first commit
This commit is contained in:
76
main.py
Normal file
76
main.py
Normal file
@@ -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
|
||||||
|
|
||||||
Reference in New Issue
Block a user