Jul-04-2020, 06:18 PM
(This post was last modified: Jul-04-2020, 06:18 PM by Daku_Chishiki.)
Hi! I just start learning Python and I wanted to push myself and try to make a little program that will verify the user position, userid and password before loading the main menu. The account credentials are store in a table in database. Below is a quick description of what I want the program to perform.
- Ask the user to enter his role one the company
Ask the user to enter his userid
Ask the user enter his password
The program should look in the database and find the record, compare the record to the credentials entered.
If credentials is correct load the main menu otherwise prompt the user to enter the correct credentials.
After three trials the user account should be locked.
My problem with the current code is that the program go through the first loop only and will never go through the validation of the credentials.
Here is how my database table look like.
userid password role
PD001 pdmanager1 Product Manager
RET001 retailer1 Retailer
SMGR001 seniormgr1 Senior Manager
SM001 smanager1 Site Manager
Below is a copy of my code.
import sqlite3 userid = "" password = "" role = "" connect_fworlddb = sqlite3.connect('fworld.db') myCursor = connect_fworlddb.cursor() myCursor.execute('SELECT * FROM account_tbl WHERE userid = ? and password = ? and role = ?',(userid,password,role)) allusers = myCursor.fetchall() for chances in range(3,0,-1): #count number of tries xrole = input("Enter your Role: ") xuserid = input("Enter UserID: ") xpassword = input("Enter Password: ") for user in allusers: #looping in allusers list to find user for credential in user: #looping on one user tuple to validate credentails if not found move to next tuple. if credential[0] == xuserid and credential[1] == xpassword and credential[2] == xrole: #validation of credentials print("You have Successfully logged in Fishing World") break else: print("Either your role, username or password is wrong.") print("You have" + " " + str(chances) + " " + "chances left.") print("Please Try Again!") if chances == 1: print("User" + " " + xuserid + " " + "account has been locked.") print("Please contact the system Administrator on ext. 5408") exit