Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Login system not working
#1
im new to python and im trying to create a login system in python 3.7.3. There are two separate files called Usernames and Passwords. When i run the code it ruturns usernames not defined.
def Files():
    with open("Passwords.txt", "r") as f:
        passwords = [line.rstrip('\n') for line in f]
        f.close
    with open("Usernames.txt", "r") as f:
        usernames = [line.rstrip('\n') for line in f]
        f.close
        return passwords, usernames

def login(usernames, passwords):
    global enter_username
    enter_username = input("Input your username")
    if enter_username in usernames:
        enter_password = input("Input your password")
        if enter_password in passwords:
            username_pos = usernames.index(enter_username)
            password_pos = passwords.index(enter_password)
            if username_pos == password_pos:
                print("well done you logged in", enter_username)
                return True
            else:
                print("your password does not match the username")
        else:
            print("password not found")
    else:
        print("username is not authorised")
    return False
            

login(usernames, passwords)
Reply


Messages In This Thread
Login system not working - by Unknown_Relic - Nov-05-2019, 10:47 AM
RE: Login system not working - by ThomasL - Nov-05-2019, 11:55 AM
RE: Login system not working - by buran - Nov-05-2019, 12:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  in a login interface when i try login with a user supposed to say test123 but nothing NullAdmin 3 2,218 Feb-20-2021, 04:43 AM
Last Post: bowlofred
  Difference between os.system("clear") and os.system("cls") chmsrohit 7 16,495 Jan-11-2021, 06:30 PM
Last Post: ykumar34
  Login and Register system finndude 1 2,355 Apr-24-2020, 10:05 PM
Last Post: deanhystad
Question Difference between Python's os.system and Perl's system command Agile741 13 6,656 Dec-02-2019, 04:41 PM
Last Post: Agile741
  Login System Carbonix 4 4,384 Feb-04-2019, 02:19 PM
Last Post: Larz60+
  Python login system help. calumw20 1 3,646 Mar-06-2018, 08:01 AM
Last Post: buran
  Creating a Login System Using Python- HELP tesilstudent112 0 9,525 Dec-08-2017, 07:17 PM
Last Post: tesilstudent112
  Login System ItsBlueey 1 36,987 Nov-06-2017, 05:24 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

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