hashlib摘要算法模块

import hashlib
md5=hashlib.md5()
md5.update(b'123456')#必须bytes类型
print(md5.hexdigest())

import hashlib
user=input('username:\n')
password=input('password:\n')
with open('user_pwd') as f:
    for line in f:
        usr, pwd, low = line.split(',')
        md5=hashlib.md5()
        md5.update(bytes(password,encoding='utf-8'))#必须bytes类型
        md5_pwd=md5.hexdigest()
        if user==usr and pwd==md5_pwd:
            print('登录成功')





 撞库

# 加盐
import hashlib   # 提供摘要算法的模块
md5 = hashlib.md5(bytes('盐',encoding='utf-8'))
# md5 = hashlib.md5()
md5.update(b'123456')
print(md5.hexdigest())

# 动态加盐
# 用户名 密码
# 使用用户名的一部分或者 直接使用整个用户名作为盐
import hashlib   # 提供摘要算法的模块
md5 = hashlib.md5(bytes('盐',encoding='utf-8')+b'')
# md5 = hashlib.md5()
md5.update(b'123456')
print(md5.hexdigest())

猜你喜欢

转载自blog.csdn.net/qq_37493425/article/details/89446692