My login system will not work – regardless of any user passwords entered

My sign up and login authentication system is not working as it is supposed to. My signup issue was fixed, but my login has a problem. Either the code will let me go through and access the account, or it will not, depending on the code. But anytime I try to fix it, the output is one of the two options. ALWAYS, regardless of the password I enter.

The usernames and passwords are stored in a txt file, like this:

John Appleseed:hisSuperSecretPassword
JohnDoe:1234

The login code:

found = False
username = input("Enter your username:n")
file = open("account.txt", "r+")
    
for line in file:
    if line.split(':')[0] == username:
        found = True
if found == True:
    password = input("Enter your password:n")

    for counter, line in enumerate(file):
            
        if line.strip() == username + ":" + password:
            print("You have signed in.")
        else:
            print("Password incorrect. Program closing.")
            sys.exit()
else:
    print("Username not valid.")
    sys.exit()

Can anyone help? Running latest Python, of course.

Answer

Here is something I’ve adjusted to work….

import sys

found = False
username = input("Enter your username:n")
file = open("account.txt", "r+")
    
for line in file:
    if line.split(':')[0] == username:
        account_details = line.split(':')
        found = True

if found == True:
    password = input("Enter your password:n")
    if account_details[1].strip() == password:
        print("You have signed in.")
    else:
        print("Password incorrect. Program closing.")
        sys.exit()
else:
    print("Username not valid.")
    sys.exit()