Hello,
I'm trying to make a login form using Python and SQLite as a database. I am able to match the Name and Password to get a successful login, but I am trying to add a third variable (Privilege) which will take the user to a different menu depending on their privilege status (admin or StandardUser ).
This is what I have so far:
My CreateUserTable.py
If the user is an admin call AdminMenu()
else if the user is a StandardUser call MainMenu()
else call CredentialsError()
Any way I can do this?
Thanks in advance.
I'm trying to make a login form using Python and SQLite as a database. I am able to match the Name and Password to get a successful login, but I am trying to add a third variable (Privilege) which will take the user to a different menu depending on their privilege status (admin or StandardUser ).
This is what I have so far:
My CreateUserTable.py
import sqlite3
def createDatabase():
#Create a database (users.db)
connection = sqlite3.connect("users.db")
cursor = connection.cursor()
table = """CREATE TABLE IF NOT EXISTS Users
(ID INTEGER PRIMARY KEY AUTOINCREMENT,
Name TEXT NOT NULL,
Password INT NOT NULL,
Privilege TEXT NOT NULL);"""
#Execute the creation of the table
cursor.execute(table)
#print("The database has been created")
#Commit the changes
connection.commit()
#Close the connection
connection.close() What's in my Table right now:Output:[('Admin', 1234, 'admin')]A snippet of my Login Code: import sqlite3
connection = sqlite3.connect("users.db")
cursor = connection.cursor()
cursor.execute(f"SELECT Name from users WHERE Name ='{userInputName}' AND Password = '{userInputPassword}';")
connection.commit()
if not cursor.fetchone(): # An empty result evaluates to False.
print("Login failed")
else:
print("Welcome")
#Close the connection
connection.close()I need to grab the Privilege column from the table and use it to determine which menu it will take the user to. If the user is an admin call AdminMenu()
else if the user is a StandardUser call MainMenu()
else call CredentialsError()
Any way I can do this?
Thanks in advance.
