当前位置: 代码迷 >> 综合 >> python常用模块(hashlib)学习之实现登录注册
  详细解决方案

python常用模块(hashlib)学习之实现登录注册

热度:87   发布时间:2024-01-26 19:56:43.0
#扩展练习:实现登录注册 用hashlib中的md5进行加密import hashlib
import redef denglu():
#登录user1 = input('请输入你的账号')pwd  = input('请输入你的密码')count = 0with open('json1.txt','r') as f:for i in f:user,passwd = i.split('|')  result_pwd = re.findall(r'\S+',passwd)[0]  res = hashlib.md5(pwd.encode())res_pwd = res.hexdigest()if user1 ==user and res_pwd == result_pwd:print('输入正确')count +=1if count ==0:print('输入错误')def zhuce():usr = input('请输入你要注册的名字')pwd = input('请输入你要注册的密码')res_pwd = hashlib.md5(pwd.encode())pwd = res_pwd.hexdigest()with open('json1.txt','a+') as f:f.write('\n'+usr+'|'+pwd)while True:try:a = int(input('请输入你要执行的操作:1.注册,2登录,3.退出'))except ValueError as f:print('问题是:%s'%f)breakif a == 1:zhuce()elif a == 2:denglu()elif a == 3:break