1 # 写一个登陆注册小程序
2 # 登录:
3 # 1.账户密码会预先记录在文件中
4 # 2.输入账号密码:如果都正确,登录成功
5 # 3.如果用户登录时进行三次校验,都不对,记录黑名单文件中
6 # 4.如果是黑名单的用户,禁止下次再次登录
7
8 # 注册:
9 # 1.检测两次密码如果相同,确认注册成功
10 # 2.检测两次密码如果不同,提示两次密码不一致
11 # 3.用户名不能重复
12 while True:
13 res = input('请问是注册还是登录?注册请输入A,登录输入B')
14 choose = res.upper()
15 def zhuce():
16 while True:
17 with open("yonghuming.txt",mode='r+',encoding='utf-8')as fp,open('mima.txt',mode='r+',encoding='utf-8')as fp1:
18 admin1=""
19 password11=""
20 yonghuming = ""
21 mima = ""
22 one = fp.readline()
23 two = fp1.readline()
24 one1=one.strip()
25 two2=two.strip()
26 lst1=one1.split()
27 lst2=two2.split()
28 admin = input('请输入注册的用户名')
29 for i in admin:
30 admin1 += i.strip()
31 if admin1 in lst1:
32 print('用户名重复')
33 continue
34 else:
35 lst1.append(admin1)
36 password1 = input('输入密码')
37 for i in password1:
38 password11 += i.strip()
39 while True:
40 password2 = input('再次确认密码')
41 password22=""
42 for i in password2:
43 password22 += i.strip()
44 if password11 == password22:
45 lst2.append(password11)
46 print('注册成功')
47 break
48 else:
49 print('两次密码不一致')
50 continue
51
52 with open("yonghuming.txt",mode='r+',encoding='utf-8')as fp,open('mima.txt',mode='r+',encoding='utf-8')as fp1:
53 for i in lst1:
54 yonghuming += i+' '
55 fp.write(yonghuming)
56 for i in lst2:
57 mima+=i+' '
58 fp1.write(mima)
59 break
60
61
62 def denglu():
63 while True:
64 with open("yonghuming.txt",mode='r+',encoding='utf-8')as fp,open('mima.txt',mode='r+',encoding='utf-8')as fp1,open('heimingdan.txt',mode='r+',encoding='utf-8')as fp2:
65 admin = ''
66 yonghuming = fp.readline()
67 mima = fp1.readline()
68 heimingdan = fp2.readline()
69 lst1 = yonghuming.split()
70 lst2 = mima.split()
71 lst3 = heimingdan.split()
72 admin1 = input('请输入登录用户名')
73 for i in admin1:
74 admin += i.strip()
75 if admin in lst1 and admin not in lst3:
76 res = lst1.index(admin)
77 elif admin in lst3:
78 print('此用户已禁止登录,查询原因请拨打110')
79 break
80 else:
81 print('无效的用户名')
82 continue
83 total = 1
84 while True:
85 password = ''
86 password1 = input('请输入密码')
87 for i in password1:
88 password += i.strip()
89 if password == lst2[res]:
90 print('登录成功')
91 break
92
93 elif password != lst2[res] and total < 3:
94 total+=1
95 print('密码错误,请重新输入密码')
96 continue
97 else:
98 fp2.write(admin+' ')
99 print('密码错误三次,被列入黑名单,此用户无法再次登录')
100 break
101 break
102
103 if choose == 'A':
104 zhuce()
105 break
106 elif choose == 'B':
107 denglu()
108 break
109 else:
110 print('让你输A或者B呢')
111 continue