项目初次搭建
This commit is contained in:
13
app/common/bcrypt_pw.py
Normal file
13
app/common/bcrypt_pw.py
Normal file
@ -0,0 +1,13 @@
|
||||
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'))
|
Reference in New Issue
Block a user