Python:bcrypt对密码进行加密和校验

安装

pip install bcrypt

使用示例

# -*- coding: utf-8 -*-

import bcrypt

passwd = '123456'

# 加密过程
salt = bcrypt.gensalt(rounds=10)
hashed = bcrypt.hashpw(passwd.encode(), salt)

print(salt)
# b'$2b$12$BlfmESsgNnsQFCmpUnhDWO'

print(hashed)
# b'$2b$12$BlfmESsgNnsQFCmpUnhDWO2RbacoHJViT8AZR1qh3DDOHnZxB.J5q'

# 校验过程
ret = bcrypt.checkpw(passwd.encode(), hashed)

print(ret) # True


上一篇:Windows 10 Build 16226发布:任务管理器新增GPU追踪


下一篇:【Centos】 kernel panic-not syncing:VFS:Unable to mount root fs on unknown block