14 lines
446 B
Python
14 lines
446 B
Python
import bcrypt
|
|
|
|
#使用bcrypt对密码进行加密
|
|
def hash_password(password):
|
|
# 生成盐值并使用 bcrypt 加密密码
|
|
salt = bcrypt.gensalt()
|
|
hashed = bcrypt.hashpw(password.encode('utf-8'), salt)
|
|
return hashed
|
|
|
|
|
|
def verify_password(provided_password, stored_password):
|
|
# 验证提供的密码是否与存储的哈希值匹配
|
|
return bcrypt.checkpw(provided_password.encode('utf-8'), stored_password.encode('utf-8'))
|