MD5
用法:
import hashlib
obj = hashlib.md5(加盐)
obj.update(明文的bytes)
obj.hexdigest() 获取密文
示例:
1 import hashlib 2 3 SALT = b"abcdefghijklmnjklsfdafjklsdjfklsjdak" 4 5 # 创建md5的对象 6 obj = hashlib.md5(SALT) # 加盐 防止破解 7 # 给obj设置明文 8 obj.update("alex".encode("utf-8")) 9 # 获取到密文 10 miwen = obj.hexdigest()
应用:
1 import hashlib 2 SALT = b"abcdefghijklmn" #随意写 3 4 def jiami(content): 5 obj = hashlib.md5(SALT) 6 obj.update(content.encode("utf-8")) 7 return obj.hexdigest() 8 9 10 # 注册 11 # username = input("请输入你的用户名:") 12 # password = input("请输入你的密码:") #456 13 # password = jiami(password) # 063ce24fb05ba5f9d7a72e50cddbcca7 14 # print(password) 15 16 #登录 17 uname = "alex" 18 upwd = "063ce24fb05ba5f9d7a72e50cddbcca7" 19 20 username = input("请输入你的用户名:") 21 password = input("请输入你的密码:") 22 23 if uname == username and upwd == jiami(password): 24 print("登录成功") 25 else: 26 print("失败")