Python Forum
Login System - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Login System (/thread-15705.html)



Login System - Carbonix - Jan-28-2019

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()



RE: Login System - Larz60+ - Jan-28-2019

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.


RE: Login System - Carbonix - Jan-31-2019

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.


Login System - Carbonix - Feb-04-2019

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.


RE: Login System - Larz60+ - Feb-04-2019

line 11 is recursion, will eventually fail
change to:
                    continue