插入密码哈希时Mysql出错

问题描述 投票:0回答:1

我将根据本教程使用mysql安装postfix:https://www.cloudsigma.com/mail-server-configuration-tutorial-how-to-use-postfix-dovecot-mysql-and-spamassassin/

我被困在插入邮件用户和相应密码的地方。这些教程似乎有点旧,并且在 mysql 中使用了加密语句,该语句已被弃用。所以我做了一点阅读,发现了新的 SHA2 声明。我根据自己的需要采用了它,当插入 mysql 时出现错误。看一下屏幕截图。像素密码是我用 dovecotadm 创建的哈希值,正如我在互联网上找到的另一篇文章中建议的那样:https://www.linode.com/community/questions/19393/encrypt-function-not-working-关注邮件服务器设置的 linode 进程

enter image description here

因为我对mysql不太了解,所以我现在陷入困境。有任何想法吗?哈希值是否正确?

mysql password-encryption
1个回答
0
投票

当然,这里有一些代码片段演示了如何使用 Python 中的 bcrypt 库对密码进行哈希和验证。 bcrypt 是一个广泛使用的用于安全散列密码的库。

安装

如果尚未安装 bcrypt 库,则需要安装。您可以使用 pip 安装它:

pip install bcrypt

哈希密码:

import bcrypt

# User's plaintext password
password = "user_password".encode('utf-8')  # Encode as bytes

# Hash the password
salt = bcrypt.gensalt()
hashed_password = bcrypt.hashpw(password, salt)

# Store the 'hashed_password' in your database

验证密码:

# User's plaintext password (from login attempt)
login_password = "user_password".encode('utf-8')  # Encode as bytes

# Retrieve the 'hashed_password' from your database based on the user's username or email

# Verify the password
if bcrypt.checkpw(login_password, hashed_password):
    print("Password is correct. Allow access.")
else:
    print("Password is incorrect. Deny access.")
© www.soinside.com 2019 - 2024. All rights reserved.