需求:
- 可以支持多个用户登录 (提示,通过列表存多个账户信息)
- 用户3次认证失败后,退出程序,再次启动程序尝试登录时,还是锁定状态(提示:需把用户锁定的状态存到文件里)
流程图:
代码:
1 div={
2 'list1':{'password':'123456'},
3 'list2':{'password':'123456'},
4 'list3':{'password':'123456'},
5 }
6 f = open('black_user','r')
7 lock_file = f.readlines()
8 f.close()
9 count=0
10 count1=0
11 while True:
12 name_input=input("please input name:")
13 if count == 3:
14 print("用户名输入次数到达限制")
15 break
16 if not name_input in div:
17 print("用户名错误")
18 count +=1
19 if name_input in lock_file:
20 print("户名已锁定,暂停使用!")
21 exit()
22
23 if name_input in div:
24 count -=2
25 password_input=str(input("please input password:"))
26 if password_input == div[name_input]['password']:
27 print ("密码成功")
28 break
29 else:
30 print("密码错误")
31 count1 +=1
32 if count1 == 2:
33 print("您输入的密码错误次数已达3次,将锁定您的账户!")
34 f = open('black_user', 'w')
35 f.write('%s'%name_input)
36 f.close()
37 break