我目前有一个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}$
{My issue}是在cd1>过程中添加的。在这个过程中,我将
password
参数设置为VARCHAR(20)
,显然不足以处理散列。愚蠢的错误。不过,塔德曼的建议对建立一个合适的数据库确实有帮助。在相关问题 更多 >
编程相关推荐