首页 > 编程语言 > 详细

python实现注册登录,密码用md5加密,但是两次加密得出的值不一样,这是为什么啊?

时间:2019-07-18 01:44:23      阅读:326      评论:0      收藏:0      [点我收藏+]
import hashlib
md5=hashlib.md5()
sha1=hashlib.sha1()
name=[]
password=[]
user={}
dict(user)
#用户注册
while True:
choice = input(‘1:用户注册\t2:验证登录\t‘)
choice = int(choice)
while choice==1:
print(‘----用户注册----‘.center(40))
name_=input(‘(用户名由数字、字母、符号组成)\n请输入要注册的用户名:‘)
name.append(name_)
password_=input(‘(密码由数字、字母、符号组成)\n请设置用户密码‘)
print(password_)
print(‘通过md5加密中...‘.center(40))
md5.update(password_.encode(‘utf-8‘))
print(md5.hexdigest())
password.append(md5.hexdigest())
#将用户名和密码保存到字典
choice1=input(‘注册成功!\b\n输入1返回\t输入2继续注册\t‘)
choice1=int(choice1)
if choice1==1:
break
else:
continue
user = dict(zip(name, password))
print(user)
#验证登录
while choice==2:
print(‘----用户登入----‘.center(40))
_name=input(‘用户名:‘)
if _name in user.keys():
_password = input(‘密码:‘)
print(_password)
print(‘md5加密中...‘.center(40))
md5.update(_password.encode(‘utf-8‘))
print(md5.hexdigest())
if md5.hexdigest()==user[_name]:
print(‘登录成功!\n欢迎使用!‘.center(40))
break
else:
print(‘密码错误!‘.center(40))
continue
else:
print(‘用户名不存在!‘.center(40))
continue

python实现注册登录,密码用md5加密,但是两次加密得出的值不一样,这是为什么啊?

原文:https://www.cnblogs.com/Zzenith/p/11204336.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!