首页 新闻 会员 周边

用python3写注册和登录代码,密码用md5加密,但是两次加密得出的值不一样,这是为什么啊?

0
[已关闭问题] 关闭于 2019-07-17 23:15

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

Zzenith的主页 Zzenith | 菜鸟二级 | 园豆:202
提问于:2019-07-17 23:14
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册