关于Python3.6下登陆接口的尝试

编者按:
README:此代码为用户登陆界面,添加了寻求帮助选项。
1.学习了基本数据类型,string, int,以及while循环,continue, break, if, elif, else条件语句,“x".format(x)变量替代
2.上网搜的dictionary用法,由于用的是Python3.6,老教程不太管用,尝试了2天方才悟出正确的增加键值用法,希望技术大牛留言给予更多启发!

关于Python3.6下登陆接口的尝试

dict_profile = {"Alex":"alex1234", "Bob":"bob123", "Cathy":"cathy1234",
                "David":"david12345", "Eva":"eva123"}
#Save the rightful username and password in the dictionary
black_list = { } #Create a list for not exist username
email = "send an email to our help desk for further solutions"
chance = 6 #After 3 valid trys the system will be locked
username = input("username:")
password = input("password:")
#password = getpass.getpass("password:")
while chance > 0:
    if username not in dict_profile.keys(): #Search for username in the profile
      black_list["{}".format(username)]="{}".format(password)
      username = input("The username does not exist, please try again:")
      chance = chance - 1
      if username in black_list.keys(): #Run a security check
        username = input("The username does not exist and has been locked, please try other combinations:")
        chance = chance - 2 # Deduct 2 chances to punish whoever abuses the system
    elif password != dict_profile.get(username,""): #Find the value of password to match with the username
      print("The password does not match the username, do you have problem with memorizing things?")
      customized_option = input("Y/N")
      if customized_option != "N":
        print("Please ask your partner or {}.".format(email))
        break
      else:
        password = input("Please enter your password with caution:")
        chance = chance - 1
    else:
        print("Welcome my lord {_name}! Please wait while login...".format(_name = username))
        break
if chance <= 0:
    print("The system is locked since you have too many incorrect entries!Please {}.".format(email))

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/d081e126c4eca0d1956aa6520666bc15.html