在我的登录方法中,我试图检查数据库中的密码是否与用户提交的密码相对应。我使用这段代码:
@app.route('/login', methods=['GET', 'POST'])
def login():
error = None
db = get_db()
if request.method == 'POST':
cur = db.execute('select password from users where username = ?', (request.form['username'], ))
password = cur.fetchone()
print password
print request.form['password']
if request.form['password'] != password:
error = 'Invalid username/password combination'
else:
session['logged_in'] = True
flash('You were logged in')
return redirect(url_for('show_entries'))
return render_template('login.html', error=error)
例如,当密码为默认密码时,打印命令显示的内容如下:
print password : (u'default',)
print request.form['password'] : default
所以他们确实是不平等的。有谁知道如何解决这个问题?