1 dict_profile = {"Alex":"alex1234", "Bob":"bob123", "Cathy":"cathy1234",
2"David":"david12345", "Eva":"eva123"}
3#Save the rightful username and password in the dictionary 4 black_list = { } #Create a list for not exist username 5 email = "send an email to our help desk for further solutions" 6 chance = 6 #After 3 valid trys the system will be locked 7 username = input("username:")
8 password = input("password:")
9#password = getpass.getpass("password:")10while chance > 0:
11if username notin dict_profile.keys(): #Search for username in the profile12 black_list["{}".format(username)]="{}".format(password)
13 username = input("The username does not exist, please try again:")
14 chance = chance - 1
15if username in black_list.keys(): #Run a security check16 username = input("The username does not exist and has been locked, please try other combinations:")
17 chance = chance - 2 # Deduct 2 chances to punish whoever abuses the system18elif password != dict_profile.get(username,""): #Find the value of password to match with the username19print("The password does not match the username, do you have problem with memorizing things?")
20 customized_option = input("Y/N")
21if customized_option != "N":
22print("Please ask your partner or {}.".format(email))
23break24else:
25 password = input("Please enter your password with caution:")
26 chance = chance - 1
27else:
28print("Welcome my lord {_name}! Please wait while login...".format(_name = username))
29break30if chance <= 0:
31print("The system is locked since you have too many incorrect entries!Please {}.".format(email)) 登陸接口