cur = conn.cursor()
result = cur.execute("SELECT * FROM users WHERE username = %s", [username])
if result > 0:
data = cur.fetchone()
password = data['password']
if sha256_crypt.verify(password_given, password):
app.logger.info('PASSWORD MATCHED')
else:
app.logger.info('PASSWORD Not MATCHED')
这是我正在使用的实际代码。我认为错误来自变量'result',我希望它将存储的密码作为字典。
答案 0 :(得分:1)
cur.execute()
没有返回结果:您必须使用cur.fetchone()
获得结果。如果没有找到结果,它将返回None
,否则它将根据使用的游标类返回元组或dict:
cur = conn.cursor()
cur.execute("SELECT * FROM users WHERE username = %s", [username])
data = cur.fetchone()
if data:
password = data['password']
答案 1 :(得分:0)
将单引号放在%s
左右,因为username
是一个字符串
result = cur.execute("SELECT * FROM users WHERE username = '%s'"%str(username))
if result.rowcount >0
Corretion
cur = conn.cursor()
result = cur.execute("SELECT * FROM users WHERE username = %s", [username])
data = cur.fetchone()
if result.rowcount > 0:
password = data['password']
if sha256_crypt.verify(password_given, password):
app.logger.info('PASSWORD MATCHED')
else:
app.logger.info('PASSWORD Not MATCHED')