Bottom Page

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()
gehrenfeld likes this post
Quote
#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.
Quote
#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.
Quote
#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.
buran wrote Feb-04-2019, 08:48 AM:
Please, keep the discussion in the original thread, don't start new one unnecessarily.
Quote
#5
line 11 is recursion, will eventually fail
change to:
                    continue
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
Question Difference between Python's os.system and Perl's system command Agile741 13 334 Dec-02-2019, 04:41 PM
Last Post: Agile741
  Login system not working Unknown_Relic 2 109 Nov-05-2019, 12:07 PM
Last Post: buran
  Difference between os.system("clear") and os.system("cls") chmsrohit 6 1,030 Jun-16-2019, 11:38 AM
Last Post: DeaD_EyE
  Python login system help. calumw20 1 1,036 Mar-06-2018, 08:01 AM
Last Post: buran
  Creating a Login System Using Python- HELP tesilstudent112 0 6,070 Dec-08-2017, 07:17 PM
Last Post: tesilstudent112
  Login System ItsBlueey 1 16,497 Nov-06-2017, 05:24 PM
Last Post: heiner55

Forum Jump:


Users browsing this thread: 1 Guest(s)