随机验证码import randomb = ''for i in range(5): t = random.randrange(0, 9) if t==3 or t==0: y = random.randrange(0,9) u1 = str(y) else: j = random.randrange(65,91) u1 = chr(j) b += u1print (b)
文本登录验证f = open('D:\E\semantic/yess.txt','r',encoding='utf-8')def func_1(user_2,pwd_2): for i in f: i1 = i.strip() i2 = i1.partition('$') if user_2 == i2[0] and pwd_2 == i2[2]: return True return Falseuser_1 = input('请输入账号:')pwd_1 = input('请输入密码')f = func_1(user_1,pwd_1)if f: print('登录成功')else: print('失败')
文本登录验证升级版f = open('D:\E\semantic/yess.txt','r',encoding='utf-8')def func_1(user_3,pwd_3): for i in f: i1 = i.strip() i2 = i1.partition('&') if user_3 == i2[0] and pwd_3 == i2[2]: return True return Falseprint('欢迎登录美国联邦系统,登录请按1,注册请按2')name = input('')if name == '2': isexit = False while not isexit: p = False user_1 = input('请输入注册账号:') for u in f: u1 = u.strip() u2 = u1.partition('&') if user_1 == u2[0]: p = True break if p: f.seek(0) print('账号已经存在') continue pwd_1 = input('请输入注册密码') print('恭喜你注册成功,欢迎登录美国联邦系统:') name_1 = '\n' + user_1 + '&' + pwd_1 f1 = open('D:\E\semantic/yess.txt','a',encoding='utf-8') f1.write(name_1) f1.flush() f1.seek(0) isexit = True breakuser_1 = input('请输入登录账号:')pwd_1 = input('请输入登录密码')r = func_1(user_1,pwd_1)if r: print('登录成功')else: print('失败')
函数版:f = open('D:\E\semantic/yess.txt','r',encoding='utf-8')def func_1(user_3,pwd_3): for i in f: i1 = i.strip() i2 = i1.partition('&') if user_3 == i2[0] and pwd_3 == i2[2]: return True return Falsedef Verify(user_name): user_pwd = input('请输入注册密码:') name = '\n' + user_name + '&' + user_pwd f = open('D:\E\semantic/yess.txt','a',encoding='utf-8') f.write(name) f.flush() Sign()def register(): while True: isexit = False isexit_1 = False user_2 = input('请输入注册账号:') for u in f: u1 = u.strip() u2 = u1.partition('&') if user_2 == u2[0]: isexit = True f.seek(0) break else: isexit_1 = True if isexit: print('账号已经存在,请重新注册。') continue elif isexit_1: f.seek(0) Verify(user_2) breakdef Sign(): inp_1 = input('欢迎登录美国联邦系统,登录请按1,注册请按2.\n') if inp_1 == '1': user_1 = input('请输入登录账号:') pwd_1 = input('请输入登录密码') r = func_1(user_1,pwd_1) if r: print('登录成功') else: print('失败') elif inp_1 == '2': register()Sign()
验证码版本:import randomf = open('D:\E\semantic/yess.txt','r',encoding='utf-8')def func_1(user_3,pwd_3): for i in f: i1 = i.strip() i2 = i1.partition('&') if user_3 == i2[0] and pwd_3 == i2[2]: return True return Falsedef Verify(user_name): user_pwd = input('请输入注册密码:') name = '\n' + user_name + '&' + user_pwd f = open('D:\E\semantic/yess.txt','a',encoding='utf-8') f.write(name) f.flush() Sign()def register(): while True: isexit = False isexit_1 = False user_2 = input('请输入注册账号:') for u in f: u1 = u.strip() u2 = u1.partition('&') if user_2 == u2[0]: isexit = True f.seek(0) break else: isexit_1 = True if isexit: print('账号已经存在,请重新注册。') continue elif isexit_1: f.seek(0) Verify(user_2) breakdef yzm(): b = '' for i in range(5): t = random.randrange(0, 9) if t==3 or t==0: y = random.randrange(0,9) u1 = str(y) else: j = random.randrange(65,91) u1 = chr(j) b += u1 return bdef Sign(): inp_1 = input('欢迎登录美国联邦系统,登录请按1,注册请按2.\n') if inp_1 == '1': y = yzm() user_1 = input('请输入登录账号:') pwd_1 = input('请输入登录密码') print(y) while True: yzm_1 = input('请输入验证码') yzm_2=yzm_1.upper() if y == yzm_2: break else: print('验证码错误') r = func_1(user_1,pwd_1) if r and y == yzm_2: print('登录成功') else: print('登录失败用户名密码错误:') elif inp_1 == '2': register()Sign()
函数升级版#验证账号def Sign_Sign(user_name): f = open('D:\E\semantic/py.txt','r',encoding='utf-8') f.seek(0) for i in f: i1 = i.strip() i2 = i1.partition('&') if user_name == i2[0]: return True return False#验证密码def pwd_pwd(user_pwd): f = open('D:\E\semantic/py.txt','r',encoding='utf-8') f.seek(0) for i in f: i1 = i.strip() i2 = i1.partition('&') if user_pwd == i2[2]: return True return False#添加新密码def modify_pwd(pwd_modify,pwd_r): f = open('D:\E\semantic/py.txt','r',encoding='utf-8') f.seek(0) list_1 = [] for i in f: i1 = i.strip() i2 = i1.partition('&') if pwd_modify == i2[0]: name = pwd_modify + '&' + pwd_r + '\n' list_1.append(name) continue list_1.append(i) print(list_1) f1 = open('D:\E\semantic/py.txt','a+',encoding='utf-8') f1.seek(0) f1.truncate() for u in list_1: f1.write(u) f1.flush print('yes')#主def Sign(): inp_1 = input('欢迎登录yellow网,登录请按1,注册请按2.修改密码请按3.\n') isexit = False #登录 if inp_1 == '1': while not isexit: user_1 = input('请输入登录账号:') pwd_1 = input('请输入登录密码') r = Sign_Sign(user_1) print(r) b = pwd_pwd(pwd_1) print(b) if r and b: print('登录成功') break else: print('用户名和密码错误,请重新输入:') #注册 elif inp_1 == '2': while not isexit: user_1 = input('请输入注册账号:') r = Sign_Sign(user_1) if r: print('账号已经存在') continue break pwd_1 = input('请输入注册密码') name = '\n' + user_1 + '&' + pwd_1 f = open('D:\E\semantic/py.txt','a+',encoding='utf-8') f.write(name) f.flush() print('恭喜注册成功,请刷新登录') Sign() #修改密码 elif inp_1 == '3': while not isexit: user_1 = input('请输入登录账号:') pwd_1 = input('请输入登录密码') r = Sign_Sign(user_1) b = pwd_pwd(pwd_1) if r and b: while not isexit: pwd_s = input('请输入新密码:') pwd_r = input('再次输入新密码') if pwd_r == pwd_s: modify_pwd(user_1,pwd_r) Sign() return else: print('两次密码不一致') else: print('用户名和密码错误,请重新输入:')Sign()
函数验证码升级版 无bug:import random#验证账号def Sign_Sign(user_name): f = open('D:\E\semantic/py.txt','r',encoding='utf-8') f.seek(0) for i in f: i1 = i.strip() i2 = i1.partition('&') if user_name == i2[0]: return True return False#验证密码def pwd_pwd(user_pwd): f = open('D:\E\semantic/py.txt','r',encoding='utf-8') f.seek(0) for i in f: i1 = i.strip() i2 = i1.partition('&') if user_pwd == i2[2]: return True return False#添加新密码def modify_pwd(pwd_modify,pwd_r): f = open('D:\E\semantic/py.txt','r',encoding='utf-8') f.seek(0) list_1 = [] for i in f: i1 = i.strip() i2 = i1.partition('&') if pwd_modify == i2[0]: name = pwd_modify + '&' + pwd_r + '\n' list_1.append(name) continue list_1.append(i) f1 = open('D:\E\semantic/py.txt','a+',encoding='utf-8') f1.seek(0) f1.truncate() for u in list_1: f1.write(u) f1.flush#验证码def vcation(): while True: vcation_str = '' for i in range(5): t = random.randrange(0, 9) if t==3 or t==0: y = random.randrange(0,9) u1 = str(y) else: j = random.randrange(65,91) u1 = chr(j) vcation_str += u1 print (vcation_str) vcation_1 = input('请输入验证码:') vcation_2 = vcation_1.upper() if vcation_2 == vcation_str: return True print('验证码错误请重新输入:')#主def Sign(): inp_1 = input('欢迎登录yellow网,登录请按1,注册请按2.修改密码请按3.\n') isexit = False #登录 if inp_1 == '1': while not isexit: user_1 = input('请输入登录账号:') pwd_1 = input('请输入登录密码') vcation() r = Sign_Sign(user_1) b = pwd_pwd(pwd_1) if r and b: print('登录成功') break else: print('用户名和密码错误,请重新输入:') #注册 elif inp_1 == '2': while not isexit: user_1 = input('请输入注册账号:') vcation() r = Sign_Sign(user_1) if r: print('账号已经存在') continue break pwd_1 = input('请输入注册密码') name = '\n' + user_1 + '&' + pwd_1 f = open('D:\E\semantic/py.txt','a+',encoding='utf-8') f.write(name) f.flush() print('恭喜注册成功,请刷新登录') Sign() #修改密码 elif inp_1 == '3': while not isexit: user_1 = input('请输入登录账号:') pwd_1 = input('请输入登录密码') vcation() r = Sign_Sign(user_1) b = pwd_pwd(pwd_1) if r and b: while not isexit: pwd_s = input('请输入新密码:') pwd_r = input('再次输入新密码') vcation() print('恭喜您已经成功修改密码') if pwd_r == pwd_s: modify_pwd(user_1,pwd_r) Sign() return else: print('两次密码不一致') else: print('用户名和密码错误,请重新输入:')Sign()