I have a python code that needs to login the user and also do the validation of inputs like check if password is good or if user excists, but I keep getting this error TypeError: 'long' object is not subscriptable??
Here is my code:
@app.route('/login', methods=['GET', 'POST'])
def login():
if g.user:
return redirect(url_for('hello'))
error = None
if request.method == 'POST':
db = MySQLdb.connect(user="root", passwd="", db="cs324", host="127.0.0.1")
c=db.cursor()
user = c.execute('''select * from user where
username = %s''', [request.form['username']])
if user is None:
error = ('Wrong username!')
elif not check_password_hash(user['password'],
request.form['password']):
error = ('Wrong password!')
else:
session['user_id'] = user['user_id']
return redirect(url_for('hello'))
return render_template('login.html', error=error)
It seems like the error occurs at the line when it checks for password and when session need to start. Any clues how I could fix this?