import hashlib def md5(arg):#这是加密函数 md5_pwd = hashlib.md5(bytes(‘meac‘,encoding=‘utf-8‘)) md5_pwd.update(bytes(arg,encoding=‘utf-8‘)) return md5_pwd.hexdigest()#返回加密的数据 def log(user,pwd): try: with open(‘login‘,‘r‘,encoding=‘utf-8‘) as f: for line in f: u,p=line.strip().split(‘|‘) if u ==user and p == md5(pwd):#登陆的时候验证用户名以及加密的密码跟之前保存的是否一样 return True return False except: return False def register(user,pwd):#注册的时候把用户名和加密的密码写进文件,保存起来 with open(‘login‘,‘a‘,encoding=‘utf-8‘) as f: temp = user+‘|‘+md5(pwd) f.write(temp) while 1: m=input(‘请您输入序号:1。代表登录,2.代表注册‘) if m==‘1‘: user=input(‘请输入登录账号:‘) pasw=input(‘请输入登录账号密码:‘) if log(user,pasw) ==False: print(‘登录失败,系统推出‘) break else: print(‘登录成功‘) elif m==‘2‘: user = input(‘请输入注册账号:‘) pasw = input(‘请输入注册账号密码:‘) register(user,pasw) print(‘注册成功‘) else: print(‘不存在你要的功能‘) break
时间: 2024-12-23 04:32:14