#扩展练习:实现登录注册 用hashlib中的md5进行加密
import hashlib
import re
def denglu():
user1 = input('请输入你的账号:')
pwd = input('请输入你的密码:')
count = 0
with open('json1.txt','r') as f:
for i in f:
user,passwd = i.split('|')
result_pwd = re.findall(r'\S+',passwd)[0]
pwd_a = '加密加密' + pwd + '#¥@¥@#@@#'
res = hashlib.md5(pwd_a.encode())
res_pwd = res.hexdigest()
if user1 ==user and res_pwd == result_pwd:
print('输入正确')
count +=1
if count ==0:
print('输入错误')
def zhuce():
usr = input('请输入你要注册的名字:')
pwd = input('请输入你要注册的密码:')
pwd_n = '加密加密' + pwd + '#¥@¥@#@@#'
res_pwd = hashlib.md5(pwd_n.encode())
pwd = res_pwd.hexdigest()
with open('json1.txt','a+') as f:
f.write(usr+'|'+pwd + '\n')
while True:
try:
a = int(input('请输入你要执行的操作:1.注册,2登录,3.退出\n:'))
except ValueError as f:
print('问题是:%s'%f)
break
if a == 1:
zhuce()
elif a == 2:
denglu()
elif a == 3:
break
python常用模块(hashlib)学习之简单实现登录注册
猜你喜欢
转载自blog.csdn.net/qq_44907926/article/details/104582428
今日推荐
周排行