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

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值