Python Forum
[Solved]Help with SQLite Login Form
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved]Help with SQLite Login Form
#1
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
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.
Reply


Messages In This Thread
[Solved]Help with SQLite Login Form - by Extra - Jun-10-2022, 11:48 PM
RE: Help with SQLite Login Form - by menator01 - Jun-11-2022, 12:48 AM
RE: Help with SQLite Login Form - by Extra - Jun-24-2022, 01:50 PM
RE: Help with SQLite Login Form - by deanhystad - Jun-24-2022, 02:17 PM
RE: Help with SQLite Login Form - by Extra - Jun-24-2022, 02:22 PM
RE: Help with SQLite Login Form - by Extra - Jun-24-2022, 02:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Solved]Help with search statement-SQLite & Python Extra 1 1,071 May-06-2022, 07:38 PM
Last Post: Extra
  in a login interface when i try login with a user supposed to say test123 but nothing NullAdmin 3 2,308 Feb-20-2021, 04:43 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020