I'm not sure if this is a duplicate as I have looked around but nothing really answered my problem. I have this school homework that I have to do over the summer and the first task is making a system the allows the user to make an account which saves to a .txt and they are then able to log in using the account they made. I am having a problem making the logging in part, even if I input the correct username and password it will not log me in.
if neworlog == 2: #Option 2, log in
logind = open("UserLoginDetails.txt","r")
username = logind.readlines()[0]
logind.seek(0)
password = logind.readlines()[1]
inputusnm = input("Please enter your username:\n")
inputpswd = input("Please enter your password:\n")
if inputusnm == username and inputpswd == password:
print("You are now logged in")
loggedin = True
else:
print("The entered username or password are incorrect")
print("Please try again")
That is my code (might be cringe worthy, idk I'm learning) for logging in. The 'logind' variable is for the .txt, the 'username' and 'password' are the variables for the correct username and password from the text file and the 'inputusnm' and 'inputpswd' variable are for the inputed username and password.
I have tried trouble shooting it. I have tried using just a normal string for the 'username' and 'password' variable and that logged me in and I also tried printing out the 'username' and 'password' variable when they were reading the .txt and it printed out the correct lines/word.
This is a picture of the .txt file:
I am kinda lost at this point and any help would be appreciated.

print(repr(username))andprint(repr(password))you'll see that end with a newline character\n. You can useusername = username.rstrip('\n')to remove it.'\n'at the end. You need to get rid of it. You can use.strip()on these strings to remove the extra spaces. Also your question isn't clear at all. The above suggestion is based on a guess that you aren't able to log in. Please edit the question and specifically ask what you need?ConfigParsermodule. Also, @Rawing, @ClockSlave are right.