注册功能
#实现注册功能
while 1:
dic={}
with open("regit.txt", mode='r+', encoding="utf-8")as fp:
res = fp.read()
#username 注册的用户名
username=input("请输入您的用户名:").strip()
#判断用户名是否重复
temp="'username': '{}',".format(username)
if temp in res:
print("用户名重复")
continue
#用户注册密码
while 1:
password = input("请您的输入密码:")
# 用户确认密码:
password2 = input("请再次您的确认密码:")
if password==password2:
print("恭喜您,账户注册成功")
break
else:
print("对不起,两次密码不一致,请重新输入")
dic["username"]=username
dic["password"]=password
with open("regit.txt",mode='a+',encoding="utf-8")as fp:
fp.write("{}\n".format(dic))
#添加推出功能
#if username.upper()=="Q":break
#实现登陆功能
登陆模块
hmd=[]
while 1:
#username:
username=input("请输入您的账户").strip()
with open("regit.txt", mode='r', encoding="utf-8")as fp:
res = fp.read()
temp = "'username': '{}',".format(username)
if temp not in res:
print("用户名不存在")
continue
with open("hmd.txt", mode='r', encoding="utf-8")as fp:
res = fp.read()
temp = "['{}']".format(username)
if temp in res:
print("您的账户异常,已被冻结,请联系管理员")
break
password=input("请输入您的密码")
with open("regit.txt", mode='r', encoding="utf-8")as fp:
res = fp.read()
temp = "'username': '{}', 'password': '{}'".format(username,password)
print(res)
if temp in res:
break
print("恭喜您登陆成功")
else:
i=2
while i>0:
print("你输入的密码错误请重新输入")
password = input("请输入您的密码")
temp = "'username': '{}', 'password': '{}'".format(username, password)
if temp in res:
break
print("恭喜您登陆成功")
i -= 1
hmd.append(username)
with open("hmd.txt",mode="a",encoding="utf-8")as fp:
fp.write("{}\n".format(hmd))
print("你输入的密码错误3次,请联系管理员!")
break