主函数:
import 登录 user = input('请输入用户名:') psw = input('请输入密码:') 登录.log_in(user,psw)
登录函数
import register
def log_in(user:str,psw:str):
with open('aa.txt', 'r', encoding='utf-8') as f:
for res in f:
res = res.strip('\n')
res_list = res.split(',')
res_name=res_list[0].split(':')
res_psw=res_list[1].split(':')
if user==res_name[1].strip(' '):
if psw == res_psw[1].strip('\n'):
print("ok")
break
else:
print("password error")
break
else:
print("用户名不存在,请注册")
register.register()
注册函数
def register():
count=1
user = input('请输入用户名:')
while True :
psw = input('请输入密码:')
psw1 = input('请再输入密码:')
if count>2 :
print("错误次数超过三次")
break
if psw == psw1 :
user_info = f'用户名:{user},密码:{psw}'
with open('aa.txt','r',encoding='utf-8') as f :
for res in f:
res_list=res.split(',')
res_name=res_list[0].split(':')
if user==res_name[1].strip():
print("用户名已存在,请重新输入")
user = input('请输入用户名:')
count = 1
break
else:
with open('aa.txt','a',encoding='utf-8') as f :
f.write(user_info+'\n')
print("注册成功")
break
else :
count += 1
print('密码不一致,请重新输入')