~~This Question is a continuation of another question.~~ I'm creating a basic Login Form and I am using Flask for serving my HTML Pages and Sqlite3 Package in python for storage of usernames and passwords!
I started by creating an App Route!
I'm requesting the User Input from the form and then comparing it with the data I retrieve from my database named 'Users.db' as follows:
@app.route('/login', methods=["GET", "POST"])
def login():
msg = ''
if request.method == 'POST' and 'username' in request.form and 'password' in request.form:
# Create variables for easy access
username = request.form['username']
password = request.form['password']
#Connection Est.
connection = sqlite3.connect("Users.db")
#cursor
USer_crsr = connection.cursor()
user_cm = """SELECT username FROM accounts where"""
user_cm_2 = """SELECT password FROM accounts"""
USer_crsr.execute(user_cm)
USer_crsr.execute(user_cm_2)
USer_result = USer_crsr.fetchall()
USer_result_2 = USer_crsr.fetchall()
if username in USer_result and if password in USer_result_2:
# Create session data, we can access this data in other routes
session['loggedin'] = True
session['id'] = USer_result['id']
session['username'] = USer_result['username']
# Redirect to home page
return 'Logged in successfully!'
else:
# Account doesnt exist or username/password incorrect
msg = 'Incorrect username/password!'
return render_template("login.html", msg=msg)
(I know this code isn't correct!)
Any suggestions on what I can do to correctly retrieve my data from the database and comparing it to the User Input?