-1

My code is always saying it is incrorrect even tough it is present on the text file, it was working before but now isn't for some reason.

def select_login_signup():
    while True:
        selection = input("Welcome to sports.com, please select"
                      " \"L\" to Log In with your account or \"S\" to create an account: ")
        if selection.lower() == 's':
            register()
            answer = input("Would you like to Log In? Y/N? ")
            while not answer:
                if answer.lower() == "y":
                    login()
                    break
                elif answer.lower() == "n":
                    exit()

                else:
                    answer = False
                    print("Invalid answer.")
                    continue
        elif selection.lower() == 'l':
            login()
            break
        else:
            print("Invalid answer.")
            continue


def register():
    username = input("Create your username (no more than 10 characters or less than 4.): ")
    while 10 < len(username) < 4:
        print('username cannot have more than 10 characters or less than 4.')
        username = input("Create your username (no more than 10 characters or less than 4.): 
")
        break
    while username.isnumeric():
        print("username must contain at least one letter")
        username = input("Create your username (no more than 10 characters or less than 4.): 
")
        break

    password = input("Create a password with letters and numbers: ")
    while len(password) < 6:
        print("Your password must contain more than 6 characters.")
        password = input("Create a password with letters and numbers: ")
        continue
    while password.isnumeric() or password.isalpha():
        print("Your password must contain both letters and numbers")
        password = input("Create a password with letters and numbers: ")
        continue

    login_credentials = open('C:\\Users\\hmarq\\Documents\\UsernameAndPassword.txt', "a")
    login_credentials.write(f'\n{username},{password}')
    login_credentials.close()

    print("Account created successfully.")


def login() -> object:
        username = input("Please enter your username: ")
        username = username.strip()
        password = input("Please enter your password: ")
        password = password.strip()
        login_credentials = open('C:\\Users\\hmarq\\Documents\\UsernameAndPassword.txt', "r")
        login_credentials.readlines()
        with open('C:\\Users\\hmarq\\Documents\\UsernameAndPassword.txt', 'r') as 
login_credentials:
            for line in login_credentials:
                login_info = line.split(",")
                if username == login_info[0] and password == login_info[1]:
                    print("Authorized")
                    authenticated = True
                    return authenticated
                else:
                    print("Incorrect credentials.")
                    username = input("Please enter your username: ")
                    username = username.strip()
                    password = input("Please enter your password: ")
                    password = password.strip()
                    continue


def main():
    select_login_signup()


if __name__ == "__main__":
    main()
mkrieger1
  • 19,194
  • 5
  • 54
  • 65

1 Answers1

0

with open('C:\Users\hmarq\Documents\UsernameAndPassword.txt', 'r') as login_credentials

when you open a file, you have to format the data and therefore the data is not the same.

if username == login_info[0] and password == login_info[1]:

I hope it serves you, greetings.

John_B
  • 41
  • 8