修复导入到MySQL选项卡时密码哈希被截断的问题

2024-09-27 09:34:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前有一个Flask应用程序,它向MySQL数据库注册用户名和密码。我的问题是使用Bcrypt来散列密码,然后将其保存到数据库中,输出的散列会被MySQL截断。我的功能如下:

class PasswordResource(Resource):
    @app.route('/password', methods=['GET'])
    @jwt_required

    def sendPassword():
        data = get_jwt_identity()
        hashed_password = bcrypt.hashpw(data['user_password'].encode('utf8'), bcrypt.gensalt())
        print(hashed_password)
        return mysqldb.addPassword("{}".format(str(data['user_name'])),"{}".format(hashed_password))

并连接到数据库:

^{pr2}$

然而,尽管我尝试了各种密码表的VARCHAR(),但该哈希仍然被MySql截断。这是我在控制台Warning: (1265, u"Data truncated for column 'p_password' at row 1") self._do_get_result()中遇到的错误。我的密码列当前配置为VARCHAR(255), Not Null。如何修复此错误并避免哈希值被截断?在

更新

这是我的密码表的架构:

^{3}$

Tags: 数据库format密码flaskdataget错误mysql

热门问题