import bcrypt def hash_password(password): """对密码进行哈希处理""" # 对密码进行加盐处理并哈希 salt = bcrypt.gensalt() hashed = bcrypt.hashpw(password.encode('utf-8'), salt) return hashed.decode('utf-8') def check_password(hashed_password, user_password): """验证密码是否匹配""" return bcrypt.checkpw(user_password.encode('utf-8'), hashed_password.encode('utf-8'))