Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Login System
#1
Hello,
I have made myself a little log in code but i have an issue,
When the account exists i get the error that the username or password is incorrect, i have looked through my code and just can not understand what i have done.
Here is the code:
def loginReg():
    welcome = input("Do you have an acount? y/n:\n>> ")
    if welcome == "n":
        while True:
            username  = input("Enter a username:\n>> ")
            password  = input("Enter a password:\n>> ")
            password1 = input("Confirm password:\n>> ")
            try:
                if username in open(username+".txt").read():
                    print ("Error: Username already exists")
                    loginReg()
            except OSError as e:
                if password == password1:
                    file = open(username+".txt", "w")
                    file.write(username+":"+password)
                    file.close()
                    welcome = "y"
                    break
                print("Passwords do NOT match!")
                loginReg()
Reply
#2
line 11 is causing recursion, where continue would suffice.
In addition, if the password is correct, you never break out of the while loop.
Please always include the entire, unaltered error message, it contains very valuable information.
Reply
#3
I think i missed a bit of the code out that may have been quite important:
def loginReg():
    welcome = input("Do you have an acount? y/n:\n>> ")
    if welcome == "n":
        while True:
            username  = input("Enter a username:\n>> ")
            password  = input("Enter a password:\n>> ")
            password1 = input("Confirm password:\n>> ")
            try:
                if username in open(username+".txt").read():
                    print ("Error: Username already exists")
                    loginReg()
            except OSError as e:
                if password == password1:
                    file = open(username+".txt", "w")
                    file.write(username+":"+password)
                    file.close()
                    welcome = "y"
                    break
                print("Passwords do NOT match!")
                loginReg()
         
    if welcome == "y":
        while True:
            login1 = input("Username:\n>> ")
            login2 = input("Password:\n>> ")
            try:
                data = open(login1+".txt", "r")
            except IOError:
                print('Error: File does not exist [001]')
                loginReg()
            file = open(login1+".txt", "r")
            file.close()
            if data == login1+":"+login2:
                print("Logged In")
                main()
            print("Incorrect username or password.")
            loginReg()
    else:
        print("Error: Invalid input")
        loginReg()
I get line 36 if im trying to log in with an account that exists
There is no actual error, its more of a bug that im unable to rid of, meaning that i cannot actually give you the error a part from the fact that it tells me that the account doesn't exists when attempting to log in even though it does exists.
Reply
#4
Hello,
I have made myself a little log in code but i have an issue,
When the account exists i get the error that the username or password is incorrect, i have looked through my code and just can not understand what i have done.
Here is the code:
def loginReg():
    welcome = input("Do you have an acount? y/n:\n>> ")
    if welcome == "n":
        while True:
            username  = input("Enter a username:\n>> ")
            password  = input("Enter a password:\n>> ")
            password1 = input("Confirm password:\n>> ")
            try:
                if username in open(username+".txt").read():
                    print ("Error: Username already exists")
                    loginReg()
            except OSError as e:
                if password == password1:
                    file = open(username+".txt", "w")
                    file.write(username+":"+password)
                    file.close()
                    welcome = "y"
                    break
                print("Passwords do NOT match!")
                loginReg()
          
    if welcome == "y":
        while True:
            login1 = input("Username:\n>> ")
            login2 = input("Password:\n>> ")
            try:
                data = open(login1+".txt", "r")
            except IOError:
                print('Error: File does not exist [001]')
                loginReg()
            file = open(login1+".txt", "r")
            file.close()
            if data == login1+":"+login2:
                print("Logged In")
                main()
            print("Incorrect username or password.")
            loginReg()
    else:
        print("Error: Invalid input")
        loginReg()
I get line 36 if im trying to log in with an account that exists
There is no actual error, its more of a bug that im unable to rid of, meaning that i cannot actually give you the error a part from the fact that it tells me that the account doesn't exist when attempting to log in even though it does exist.
Reply
#5
line 11 is recursion, will eventually fail
change to:
                    continue
Reply


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,492 Jan-11-2021, 06:30 PM
Last Post: ykumar34
  Login and Register system finndude 1 2,352 Apr-24-2020, 10:05 PM
Last Post: deanhystad
Question Difference between Python's os.system and Perl's system command Agile741 13 6,650 Dec-02-2019, 04:41 PM
Last Post: Agile741
  Login system not working Unknown_Relic 2 2,225 Nov-05-2019, 12:07 PM
Last Post: buran
  Python login system help. calumw20 1 3,643 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,984 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