#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Posts
    15
    Rep Power
    0

    Username and password


    HI guys

    I need help with my code, I want to create a username and password login python program but I am not getting the right results. so far I got it to only read the first row, but sure how I can read the text in the second third row.

    e.g:
    john 12
    mic 13
    adam 13

    It only reads john and 12 at this stage. and not the rest from column 0 or 1. Can you please lte me know were I am going wrong with my code please.


    Code:
    def user_name():
        with open("password.txt","r") as access:
            text = access.read().strip().split()
            for line in access:
                lines = line.split
                s = lines[0]
            while True:
                try:
                    s = input("Enter a Username: ")
                    if s == "":
                        continue
                    if s in text[0]:
                        print("Username is correct ")
                        break
                    raise Exception("No such string found, try again")
                except Exception as e:
                    print(e)
     
    def password():
       with open("password.txt","r") as access:
            text = access.read().strip().split()
            for line in access:
                lines = line.split
                s = lines[1]
            while True:
                try:
                    s = input("Enter Password: ")
                    if s == "":
                        continue
                    if s in text[1]:
                        print("Password is correct")
                        break
                    raise Exception("No such string found, try again")
                except Exception as e:
                    print(e)
     
     
     
    user_name()
    password()
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,843
    Rep Power
    509
    Code:
    '''
    john 12
    mic 13
    adam 13
    '''
    
    def user_name():
        with open("password.txt","r") as access:
            text = access.read().strip().split()    # access.read() loads the entire file.
            print(text)
            for line in access:                     # access file position is at the far end
                print("you'll never see this")      # hence you'll never see this!
                lines = line.split
                s = lines[0]
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo