I need help with user authentication in my website. I am using python flask, sqlite3 and DB Browser for SQLite. I'm having trouble with the login part. Each time I try to login and redirect to an html website it says error 404.
Here is the code for the login page:
PackageDrop LoginUsername:
Password:
The page that is forwarded to is just simple html, nothing special so I am not uploading it.
If you feel like you need more information to understand, ask and I will post quickly.
Thanks for all the help I get.
EDIT1:
Changed in the login.html the form action from "login.html" to "login" and now it gives a 400 Bad Request error.
EDIT2:
The redirection works. I have changed the code for the login but it makes this error: "ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 7812 and this is thread id 7388". The only thing that I did is just connect to the database like this:
conn = sqlite3.connect('database.db')
This is the new code for the login:
@app.route('/login', methods=['GET', 'POST'])
def login():
error = None
checkP = conn.execute('select pword from users where uname = request.form[\'username\']')
arrayCheck = checkP.fetchall()
if request.method == 'POST':
if request.form['password'] != arrayCheck[[0][0]]:
error = 'Incorrect password'
return redirect(url_for('login.html'))
elif len(arrayCheck) == 0:
error = 'Username or password is incorrect'
return redirect(url_for('login.html'))
else:
session['logged_in'] = True
flash('You are logged in')
return redirect(url_for("userpage"))
return render_template('login.html')