Python Forum
Login Module Help - Comparing data in a text file to data held in a variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Login Module Help - Comparing data in a text file to data held in a variable
#1
def existingUser():
    userID = input("Please enter your username: ")
    password =input("Please enter your password: ")
    for line in open("database.txt","r").readlines():
        loginDetails = line.split()
        csv1= csv.reader("database.txt", delimiter = ',')
    if userID == loginDetails[0] and password == loginDetails[1]:
        print("Welcome "+(userID))
    else:
        create=input("You do not have an account, would you like to create one?")
        if create == "Yes":
            newuser()
        else:
            end()
    home= input("Hello" +(userID) + "Would you like to """"
    1: enter homework task
    2: check your progress""")
    if home == "1":
        homework()
    elif home =="2":
    
            
        print("Incorrect password")
    return False 

def newUser():
    databasefile = open("database.txt","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")
    logindata= open("database.txt", "a+")

    line= databasefile.write(userID +"," + password + "," + FirstAlevel+ "," + SecondAlevel + "," + "," + ThirdAlevel + "\n")
    databasefile.close()
    print("Welcome " + (userID) + ", your account has been created, would you now like to..")
    login=input("1.Login 2.Quit")
    if login == "2":
        sys.exit(0)
    elif login =="1":
        main()

def end():
    sys.exit(0)

def main():

    #These are the two options available
    print("Welcome to MyOnline Homework Diary")
    print("-----------------------------------")
    signIn = (int(input("""Would you like to...
    1: Register
    2: Sign In""")))
    if signIn == 1 :
        newUser()
    elif signIn ==2 :
        existingUser()
    else:
        print ("See you later!")
main()
       
       
My code is not allowing any users that have already created an account to sign in and I am not sure why as I am using the csv function to split and read the file but the code is not comparing whats in the text file to the data inputted.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation URGENT: How to plot data from text file. Trying to recreate plots from MATLAB JamieAl 4 3,473 Dec-03-2023, 06:56 AM
Last Post: Pedroski55
  Newbie here. Create an array from file data? Rayj00 2 1,199 Jan-13-2023, 01:35 PM
Last Post: perfringo
  Changing the content of the table and saving the new data into another file femke_pythonquestion123 1 1,543 Sep-18-2020, 12:06 PM
Last Post: femke_pythonquestion123
  Working with text data APK 4 2,429 Aug-22-2020, 04:48 AM
Last Post: buran
  configparser module, when use text file to show following error mbilalshafiq 5 5,033 Jul-14-2020, 04:06 PM
Last Post: mbilalshafiq
  Read data from a CSV file in S3 bucket and store it in a dictionary in python Rupini 3 6,883 May-15-2020, 04:57 PM
Last Post: snippsat
  Using an integer to manipulate a string/text variable rexyboy2121 1 1,703 Apr-22-2020, 01:37 AM
Last Post: michael1789
  Read text file, process data and print specific output Happythankyoumoreplease 3 2,849 Feb-20-2020, 12:19 PM
Last Post: jefsummers
  Data extraction from (multiple) MS Word file(s) in python Den0st 8 7,768 Sep-19-2019, 10:07 PM
Last Post: Den0st
  Convert text from an image to a text file Evil_Patrick 5 4,216 Jul-30-2019, 07:57 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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