python passlib生成Hash密文并进行验证--Hash a password with passlib
2016-06-03 08:14
921 查看
encrypt()-
generate new salt, return hash of password.
verify()-
verify password against existing hash.
from passlib.hash import sha256_crypt
password = sha256_crypt.encrypt("password")
password1 = sha256_crypt.encrypt("password")
print(password)
print(password1)
print(sha256_crypt.verify("password", password))
identify()-
check if hash belongs to this algorithm.
>>> # attempting to call verify() with another algorithm's hash will result in a ValueError: >>> from passlib.hash import sha256_crypt, md5_crypt >>> other_hash = md5_crypt.encrypt("password") >>> sha256_crypt.verify("password", other_hash) Traceback (most recent call last): <traceback omitted> ValueError: not a valid sha256_crypt hash >>> # this can be prevented by using the identify method, >>> # determines whether a hash belongs to a given algorithm: >>> hash = sha256_crypt.encrypt("password") >>> sha256_crypt.identify(hash) True >>> sha256_crypt.identify(other_hash) False
官方文档:https://pythonhosted.org/passlib/password_hash_api.html
相关文章推荐
- Python 中的 sorted()
- Python 中的 filter()
- Python 中的 map() reduce()
- Python中利用Scipy包的SIFT方法进行图片识别的实例教程
- 详解字典树Trie结构及其Python代码实现
- 详解duck typing鸭子类型程序设计与Python的实现示例
- Python的Django中将文件上传至七牛云存储的代码分享
- Python核心编程-第七章课后题
- python下根据csv将数据集按照类别分文件夹放置
- python 笔记
- python bitwise and or operator VS logical operator
- (转) Quick Guide to Build a Recommendation Engine in Python
- python读取文件中的一行有效数据
- Python编码介绍——encode和decode
- IDAPython: importing “site” failed
- 12、Python 文件处理
- leetcode 74. Search a 2D Matrix-矩阵搜索|二分查找
- python问题:IndentationError:expected an indented block错误解决
- Python Flask Web 第五课 —— 包含导航条的程序基模板
- python egg