定义函数完成注册和登录功能

def register():
while 1:
import os
check = input("退出注册请按Q或q")
if check.upper() == "Q":
break
else:
username = input("请输入用户名:")
password = input("请输入用户名密码(禁止使用“_”) :")
with open("11.txt", mode="r", encoding="utf-8") as f1,\
open("11.txt_副本", mode="w", encoding="utf-8") as f2:
count = 1
for line in f1:
f2.write(line)
s = line.strip().split("_")
if username == s[0]:
count = count +1
if count > 1:
print("用户名已被注册")
else:
f2.write(username + "_" + password + "\n")
os.remove("11.txt")
os.rename("11.txt_副本", "11.txt")





===========================================================================

def regit():
print("欢迎进入注册系统")
while 1:
B = input("退出请按Q\q")
if B.upper() == "Q":
break
else:
username = input("请输入用户名:")
password = input("请输入密码:")
with open("11", mode="r+", encoding="utf-8") as f:
for line in f:
if username == line.split("@@")[0]:
print("该用户已被注册!")
break
else:
f.write("\n" + username + "@@" + password)
return
regit()
def login():
print("欢迎进入登录系统!")
while 1:
username_1 = input("请输入用户名:")
password_1 = input("请输入密码:")
with open("11", mode="r", encoding="utf-8") as f1:
for line in f1:
if username_1 == line.split("@@")[0] and password_1 == line.split("@@")[1]:
print("登录成功!")
return
else:
print("用户名或密码错误,请重新登录!")
login()


def login():
while 1:
check = input("退出登录请按Q或q:")
if check.upper() == "Q":
break
else:
username = input("请输入用户名:")
password = input("请输入密码:")
with open("11.txt", mode="r", encoding="utf-8") as f:
count = 0
for line in f:
u, p = line.strip().split("_")
if username == u and password == p:
count = count +1
if count == 1:
print("登录成功")
else:
print("密码或用户名错误,请重新登录!")
register()
login()
posted @ 2019-11-01 15:49  冰灬荷  阅读(234)  评论(0编辑  收藏  举报