注册登录-简易代码
def signup(): with open("C:\\Users\\Administrator\\Desktop\\账号密码.txt","r") as f: line=f.read() line=eval(line) flag=False while True: global username1 username1 = input("输入注册账号:") for i in line: if i["username"]==username1: print("账号已存在") break else: if username1[0].isalnum(): if len(username1) in range(5,12): for i in range(1,len(username1)): if (username1[i].isalnum()) or (username1[i]=="_"): print("账号可以使用") flag=True break else: print("账号由数字、字母、下划线组成") break else: print("账号由5到12位数字、字母、下划线组成") break else: print("数字字母作为账号首位") break if flag == True: break while True: password1=input("输入注册密码:") password2 = input("再次输入注册密码:") if password1 != password2: print("密码不同") else: break submit=input("输入1提交,输入2取消") if int(submit)==1: data={} data["username"]=username1 data["password"]=password1 with open("C:\\Users\\Administrator\\Desktop\\账号密码.txt", "r") as f: line = f.readlines() list_=eval(line[0]) list_.append(data) with open("C:\\Users\\Administrator\\Desktop\\账号密码.txt", "w") as f: f.write(str(list_)) elif int(submit==2): exit(0) def signin(): print("请登录") flag=True while True: a = input("输入账号:") with open("C:\\Users\\Administrator\\Desktop\\账号密码.txt","r") as f: line=f.read() line=eval(line) for i in line: if i["username"] == a: flag = False break if flag == False: break else: print("账号不存在") b=input("输入密码:") c=int(input("输入1提交")) if c==1: with open("C:\\Users\\Administrator\\Desktop\\账号密码.txt", "r") as f: line = f.read() line = eval(line) flag=True for i in line: if i["username"] == a and i["password"]==b: print("已登录") flag=False break if flag=="Ture": print("密码错误") else: exit(0) while True: choose=int(input("输入1申请,输入2登录,输入0退出")) if choose==1: signup() signin() if choose==2: signin() if choose==0: break
本文来自博客园,作者:Iving,转载请注明原文链接:https://www.cnblogs.com/SAS-T/p/9382990.html