1 # python_zhangzengqiang
2
3 a = open("user.txt")
4 b = a.readlines()
5 a.close()
6 a2 = open("lock.txt")
7 b2 = a2.readlines()
8 a2.close()
9 loginsucess = False
10 while True:
11 username = input("请输入账号或输入'new'创建账号:").strip()
12 if username == "new":
13 while True:
14 newname = input("请输入账号:").strip()
15 if len(newname) != 0:
16 while True:
17 newpwd = input("请输入密码:").strip()
18 if len(newpwd) != 0:
19 a3 = open("user.txt","a")
20 a3.write(newname+" "+newpwd+"\n")
21 a3.close()
22 print("注册成功!")
23 exit()
24 else:
25 print("密码不能为空,请重新输入!")
26 continue
27 else:
28 print("账号不能为空,请重新输入!")
29 continue
30 for i2 in b2:
31 i2 = i2.split()
32 if username == i2[0]:
33 print("该账号已被锁定!")
34 exit()
35 if len(username) != 0:
36 for i in b:
37 i = i.split()
38 if username == i[0]:
39 for x in range(3):
40 password = input("请输入密码:").strip()
41 if password == i[1]:
42 loginsucess = True
43 break
44 else:
45 print("密码错误!")
46 else:
47 print("连续输入密码失败超过3次,账号已被锁定登录!")
48 a1 = open("lock.txt","a")
49 a1.write(username+"\n")
50 a1.close()
51 exit()
52 if loginsucess is True:
53 print("登录成功,欢迎回家!")
54 break
55 elif loginsucess is False:
56 print("账号错误,请重新输入!")
57 else:
58 print("账号错误,请重新输入!")
59 continue