Python Forum
Using SQLite - can't match my input password to the stored one
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using SQLite - can't match my input password to the stored one
#1
import sys
import sqlite3
#Program #1 - Main Page : Login or Register
#existingUser codes for a user that already has an account 
def existingUser():
    userID = input("Please enter your username: ")
    password =input("Please enter your password: ")
    for line in open("database.csv","r").readlines():
        loginDetails = line.split()
        if userID == loginDetails[0] and password == loginDetails[0]:
            print("Welcome"+userID)
            return True
    
    print("Incorrect password")
    existingUser()
    return False        
    
                    
   
#newUser codes for a user that doesn't already have an account and is making one   
def newUser():
    databasefile = open("database.csv","a") 
    userID = input("Enter your username")
    #this checks the password is valid
    incorrectPass= False
    while not incorrectPass:
        password= (input ("Enter a password between 5 to 8 characters"))
        length = len(password)
        if len(password) <3 or len(password)> 9:
            print("Sorry, password must be between 5-8 characters, your password is only ", length, " characters long")
        else:
            #setflag for strength test
            lowerCase =0
            upperCase =0
            digitCase=0


            for ch in password:

                if ch.islower():
                    lowerCase =1
                if ch.isupper():
                    upperCase= 1
                if ch.isdigit():
                    digitCase= 1
            #Strength output
            passwordStrength = upperCase + lowerCase + digitCase
            if passwordStrength ==1:
                print("This is a weak password")
            elif passwordStrength==2:
                print("This is a medium password")
            if passwordStrength ==3:
                print("This is a strong password")
            incorrectPass= True

    FirstAlevel= input("Enter first A-level")
    SecondAlevel=input("Enter second A-level")
    ThirdAlevel=input("Enter third A-level")
    databasefile.write(userID + "," + password + "," + FirstAlevel + "," + SecondAlevel + "," + ThirdAlevel + "," + "/n")
    databasefile.close()
    sys.exit(0)


def main():
    #These are the two options available
    print("Welcome to MyOnline Homework Diary")
    print ("1: register")
    print("2: login")
    signIn = (input("Do you have an existing account? Y or N?"))
    if signIn == "N":
        newUser()
    elif signIn =="Y":
        existingUser()
main()
#message
Hi,
I am an A-level student currently designing an online homework tracker as my project for my OCR Computer Science course. I am having problems with the code for my login.
At the moment, I am using a database on excel to store my username and password details and my system for registering a user works fine. However, when I want to login as the user I just registered I cannot find a way to search my database to match the username and password to the one located in the database. Right now, this is my code (above) and it just prints out "Incorrect Password" for every username and password I input.
The database is stored as a .csv file.
Thanks in advance for your help
Kezia
Reply
#2
I see your import of sqlite3, but absolutely no use of same,

your post title imply's  that sqlite3 is to blame for your problems,
Quote:Using SQLite - can't match my input password to the stored one
what you call a database is simply a text file with a .csv suffix.
Reply
#3
Hello,

I think that there is a typo on line 10.
if userID == loginDetails[0] and password == loginDetails[0]:
should be:
if userID == loginDetails[0] and password == loginDetails[1]:
Reply


Forum Jump:

User Panel Messages

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