hashlib
来源:互联网 发布:淘宝网首页官网床垫 编辑:程序博客网 时间:2024/05/23 01:34
hashlib 包含众多加密方法,包括:
md5,SHA1 ,SHA224,SHA256,SHA284等。
md5为不可逆加密算法,无法被反解,但是可用通过撞库解决。
import hashlibt = hashlib.md5()t.update(bytes("RootAdmin",encoding="utf-8"))print(t.hexdigest())
t.update 中可以写密码和字符编码,但这种方法可用通过撞库解决
在md5加密过程中,添加自己的专属字符串,可用达到无法解密的作用。
from hashlib import md5hash = md5(bytes("ad;'sadf'as'", encoding="utf8"))hash.update(bytes("123456", encoding="utf8"))print(hash.hexdigest())
在md5(bytes(“ad;…..”))中,使用了自己的字符串,加密,保证了加密后的字符串不被撞库破解。
通过Md5实现一个加密的登录注册程序:
**init.py**try: import cPickle as pickleexcept ImportError: import pickledef init(): users = {} with open("DB", "wb") as f: f.write(pickle.dumps(users))**main.py**import hashlibimport pickledef md5(arg): t = hashlib.md5(bytes("ad;ddafd;as;", encoding="utf-8")) t.update(bytes("arg", encoding="utf-8")) return t.hexdigest()def login(arg1, arg2): with open("db", "rb") as f: users = pickle.loads(f.read()) print(users) if users[arg1] == md5(arg2): print("login success") else: print("login fail")def register(arg1, arg2): global users with open("DB", "rb+") as f: users = pickle.loads(f.read()) users[arg1] = md5(arg2) print(users) with open("DB", "wb") as f: f.write(pickle.dumps(users))t = input("please input 1 to choose register,2 to login")if t == "1": username = input("Please input your username:") password = input("Please input your password:") register(username,password)elif t == "2": username = input("Please input your username:") password = input("Please input your password:") login(username,password)**checkout.py**try: import cPickle as pickleexcept ImportError: import pickledef check(): with open("DB", "rb") as f: users = pickle.loads(f.read()) print(users)check()
阅读全文
0 0
- hashlib
- hashlib
- hashlib
- hashlib
- hashlib
- hashlib
- python hashlib
- hashlib简介
- hashlib模块
- hashlib模块
- python hashlib moudle
- Python hashlib模块
- python模块之hashlib
- Python 2.4 安装 hashlib
- Python hashlib模块
- python模块之hashlib
- python hashlib模块
- hashlib 简单使用方法
- Go在Linux下的环境变量配置
- .ftl文件 是什么文件
- MySQL主从配置-简单测试
- HTML,CSS,JS实现网页聊天窗口
- HADOOP权威指南 第3版 PDF电子书下载 带目录书签 完整版
- hashlib
- Ubuntu 安装 nodejs
- org.hibernate.StaleStateException
- 中国IT界的风投
- Keras入门课3 -- 使用CNN识别cifar10数据集
- Codeforces #441 Div1.D:(扩展Lucas)
- leetcode candy分糖果问题 两次遍历和一次遍历
- python数据挖掘
- Vuejs全家桶系列(三)--- 生命周期和钩子函数