Python:Werkzeug.security对密码进行加密和校验

安装

pip install Werkzeug

使用示例

# -*- coding: utf-8 -*-
from werkzeug.security import generate_password_hash, check_password_hash

# 加密,每次执行都生成不一样的结果
print(generate_password_hash('123456'))
# pbkdf2:sha256:150000$MNuGXsZ5$70327cb9dcbb591c80d5c953c683745422e7a124c6207c4fd0a5db89c94fd24a
# pbkdf2:sha256:150000$mrcVlodY$94d50e91227ebd05e136f933e85978c5906e6584163b562dc7e8639ac2dce06e
# pbkdf2:sha256:150000$TaP4i3gt$b2c5c4956d756ed93d4c4f234ef45282617666a238e87284889dc7f9e375df72

# 校验
pwhash = 'pbkdf2:sha256:150000$hd5XwWvR$cda4af94834d7b9fee422eb3f3a4cd77c3cfdd29aa5fe996ce49e772e631ab19'
print(check_password_hash(pwhash, '123456'))
# True

类似的工具还有:

上一篇:CuckooSandbox


下一篇:【Flask】Flask Werkzeug版本兼容问题