我得到了以下错误,预期的是sha256_crypt hash,得到的却是sha256_crypt config string。
预期的sha256_crypt哈希值,得到的是sha256_crypt配置字符串。
这是我的代码,我做错了什么?
code :
@app.route('/login' , methods=['GET' ,'POST'])
def login():
if request.method == 'POST':
#Get form fields
username = request.form['username']
password_candidate = request.form['password']
#Create cursor
cur = mysql.connection.cursor()
#Get user by username
result = cur.execute("SELECT * FROM users WHERE username = (%s)", [username])
app.logger.info(result)
if result > 0:
#Get stored hash
data = cur.fetchone()
password = data['password']
app.logger.info(password)
#Comparing the passwords
if sha256_crypt.verify(password_candidate, password):
app.logger.info('PASSWORD MATCHED')
app.logger.info(password_candidate)
#Passed
sesion['logged_in'] = True
session['username'] = username
flash('You are now logged in', 'succes')
return redirect(url_for('about'))
else:
error = "Invalid login"
return render_template('login.html', error=error)
#Close connection
cur.close()
else:
error = 'Username not found'