手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

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

[日期:2017-12-20] 来源:Linux社区  作者:SuperGokuBeta [字体: ]

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

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

登陆接口

本文永久更新链接地址http://www.linuxidc.com/Linux/2017-12/149629.htm

linux
相关资讯       Python3.6登陆接口 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款