# 4.1:编写用户登录接口
# 4.2:编写程序实现用户注册后(注册到文件中),可以登录(登录信息来自于文件)

login = 1
while login:
Inp_zz = input('登录 1/注册 2: ').strip()
if Inp_zz == '1':
Inp_User = input('请输入用户: ').strip()
Inp_Pass = input('请输入密码: ').strip()
with open('a.txt',mode='rt',encoding='utf-8') as f3:
for g in f3:
username,password = g.strip().split(':')
if Inp_User == username and Inp_Pass == password:
print('登录成功')
login = 0
break
else:
print('用户或密码错误,请重新登录')
elif Inp_zz == '2':
with open('a.txt',mode='rt',encoding='utf-8') as f1:
Inp_rtu = input('用户: ').strip()
Inp_rtp = input('密码: ').strip()
for i in f1:
res1,_=i.strip().split(':')
if Inp_rtu.startswith(res1):
count = 1
break
else:
count = 2
if count == 1:
print('用于已存在,请重新注册')
continue
elif count == 2:
if len(Inp_rtu) != 0 and len(Inp_rtp) != 0:
with open('a.txt',mode='r+b') as f2:
f2.seek(0,2)
us='{}:{}\n'.format(Inp_rtu,Inp_rtp)
f2.write(us.encode('utf-8'))
print('注册成功,请重新登录')
else:
print('无效用户')
print()
break
else:
print('非法输入')
continue

#加油学,加油学,加油学