练习一

users_info={'xiaoming':['123','age=23','wo shi a yangguangboy'],'xiaoxu':['456','age=24','wo shi a yangguanggirl']}

fail_count = 0
flag = True
fail_list = []
count = 1
while flag:

  user = input("请输入用户名:")
  password = input("请输入密码:")

  if user == '' or password == '':

    print("输入用户名或密码不能为空,请重新输入")
    continue

 

#验证输入的用户名时否在黑名单里
  with open('heimingdan.txt', 'r') as file:
    while True:
      line = file.readline().strip()
      # print(line)

      if user == line:
        count = count-1
        break

      if line == '':
        break
    # print(count)
    if count == 0:
      print("该用户登陆失败已超出次数,请明天再登陆")
      break

 


  if user in users_info.keys() and users_info[user][0] == password:
    print("登陆成功")
    # print(fail_count)
    fail_count = 0
    break
  else:
    if user in users_info.keys():
      fail_count=fail_count+1

      # print(fail_count)
    if fail_count == 3:
      # fail_list.append(user)
      # print(fail_list)
      with open('heimingdan.txt','a') as file:
        file.write(user.strip()+'\n')
      print("错误超出了3次,今天不能再登陆了")
      break
    print("账户密码错误,请重新输入:")
    continue

posted @ 2019-01-02 14:51  冥想心灵  阅读(159)  评论(0编辑  收藏  举报