不是有效的 sha512_crypt 散列 Python Flask 错误
not a valid sha512_crypt hash Python Flask Error
嘿,出于某些原因,我每次尝试在登录页面上登录时都会收到此错误 not a valid sha512_crypt hash
。
注册页面:
username = request.form['username']
password = sha512_crypt.encrypt((str(request.form['password'])))
email = request.form['email']
cur.execute("INSERT INTO users (name,password,email) VALUES (?,?,?)",(username,password,email)
我的登录页面:
data = cur.execute("SELECT password FROM users WHERE name= ?", (request.form['username'],))
data = cur.fetchone()[0]
if sha512_crypt.verify(request.form['password'], data):
session['logged_in'] = True
session
#etc #etc #etc
因此,当我从我的数据库中填写用户名和密码时,出现错误:
not a valid sha512_crypt hash
在我的数据库中有加密密码,所以我的 sha256 加密在理论上是有效的。
您的数据库中有使用 sha256_crypt
和 sha512_crypt
创建的密码哈希,但您正在使用 sha512_crypt
来验证两者。那不行。
要么使用 sha256_crypt
(以 $
开头)创建的散列为用户重新创建密码,要么使用 passlib.apps.custom_app_context
,以验证两者。这是来自 the docs 的示例:
# import the context under an app-specific name (so it can easily be replaced later)
from passlib.apps import custom_app_context as pwd_context
# encrypting a password...
hash = pwd_context.encrypt("somepass")
# verifying a password...
ok = pwd_context.verify("somepass", hash)
嘿,出于某些原因,我每次尝试在登录页面上登录时都会收到此错误 not a valid sha512_crypt hash
。
注册页面:
username = request.form['username']
password = sha512_crypt.encrypt((str(request.form['password'])))
email = request.form['email']
cur.execute("INSERT INTO users (name,password,email) VALUES (?,?,?)",(username,password,email)
我的登录页面:
data = cur.execute("SELECT password FROM users WHERE name= ?", (request.form['username'],))
data = cur.fetchone()[0]
if sha512_crypt.verify(request.form['password'], data):
session['logged_in'] = True
session
#etc #etc #etc
因此,当我从我的数据库中填写用户名和密码时,出现错误:
not a valid sha512_crypt hash
在我的数据库中有加密密码,所以我的 sha256 加密在理论上是有效的。
您的数据库中有使用 sha256_crypt
和 sha512_crypt
创建的密码哈希,但您正在使用 sha512_crypt
来验证两者。那不行。
要么使用 sha256_crypt
(以 $
开头)创建的散列为用户重新创建密码,要么使用 passlib.apps.custom_app_context
,以验证两者。这是来自 the docs 的示例:
# import the context under an app-specific name (so it can easily be replaced later)
from passlib.apps import custom_app_context as pwd_context
# encrypting a password...
hash = pwd_context.encrypt("somepass")
# verifying a password...
ok = pwd_context.verify("somepass", hash)