gpt4 book ai didi

python - 在 MongoDB 中存储加密密码时出现问题

转载 作者:太空宇宙 更新时间:2023-11-03 18:49:43 25 4
gpt4 key购买 nike

我正在使用此处描述的技术:https://pypi.python.org/pypi/scrypt/

这是我的注册功能的代码:

@app.route('/register', methods=['POST', 'GET'])
def register():
result = db.users.find_one({"username" : flask.request.form['username']})
if result is not None:
return "That User Is Taken :("
else:
pw = scrypt.encrypt(random_token(), str(flask.request.form['password']))
db.users.insert(
{"username" : flask.request.form['username'],
"password" : pw
})
return "Registration Successful"

但是我收到以下错误:

InvalidStringData: strings in documents must be valid UTF-8: "scrypt\x00\x11\x00\x00\x00\x08\x00\x00\x00\x03\xc3g\xfez\xf3y\x06\x11\x17\x14>\xb3\xc6\x87\xd7\xc0[\x12\xae\x04N/\x1b\xc0SpK]i\n\x1c\x99{\xbeQk~n\xce\xd3\x0b\xcc\x82\xc9B\xcec\xdd\x02 \xa0\t\xda\xc9\xce~\xfd\x9a!\xa9_\xc3\n\xcet\xfd\xaf\xd9\xe0iL\x85\xb9C\x07\xc1VD\xfa\x1d\xb7\xa6\x0f\xa5t\xfao\xa2w\xb8\xd5\xdf\x00\x9f&\x8a\x96\x0e\x9c\rGz\x1a\x80\x1c\xd6\x13T\xea\xc6\x16\x8a^\xc5_W+X86\x14\xc6T\xc4\xa1\x81[N\x14H\xc5\xc4\xab\x192z\xfcD'x\x19X\x8f\xe9m?\xab\xb9\xeb~-\xb2-\x06z\xa4,\x1cS\x82\x8a\xe2!\xe0\x01^\xd0\xc9\x9e\xbc\x94}\xbe\x8c\xbc\x9d"

知道可能发生什么情况以及如何解决它吗?

最佳答案

您的加密调用会返回需要在插入 mongodb 之前编码为 UTF8 的字节。调用 unicode(pw, "utf-8") 进行转换。

关于python - 在 MongoDB 中存储加密密码时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18648728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com