python3 实现用户三次输入错误记录黑名单并对该用户登录锁定-day1

python3 实现用户三次输入错误记录黑名单并对该用户登录锁定.

 1 # Author:student
 2 import getpass  #输入密码时密文,这个输入不能通过pycharm执行
 3 import re
 4 _username = 'justtest'
 5 _password = 'Dell@123'
 6 
 7 #print(username,password)
 8 count =0
 9 username = input("username:")
10 lockfile = []
11 f = open('lockuser.txt','r',encoding='gbk')
12 lockfile = f.readline()
13 f.close()
14 list = []
15 for line in open("lockuser.txt"):
16     line1 = line.strip('\n')
17     list.append(line1)
18 if username in list:
19     print ("is locked")
20 else:
21     while count <=3:
22         if count == 3:
23             print("you try too many times for the password and your account will locked")
24             f = open('lockuser.txt', 'a', encoding='utf-8')
25             f.write(username+"\n")
26             f.close()
27             break
28         else:
29             #password = getpass.getpass("password")
30             password = input("password:")
31             if _username == username and _password == password:
32                 print("Welcome user {name} login....".format(name=username))
33                 break
34             else:
35                 print("Invalid username or password!")
36                 count +=1

 

posted on 2018-03-20 17:16  影子在原野  阅读(160)  评论(0编辑  收藏  举报

导航