import time file = open("login.txt","r") TrueUsername = file.readline(1) TruePassword = file.readline(2) print("Log in") time.sleep(0.5) Username1 = input("Username:") Password1 = input("Password:") if Username1 == TrueUsername and Password1 == TruePassword: print("Welcome.") else: print("Try again.") file.close()---Whenever I write the correct password and username on the .txt file it prints "Try again."
Why doesn't this work?
Why doesn't this work?
|
Apr-16-2018, 02:01 PM
There you go.
Apr-16-2018, 02:12 PM
you should use configparser.
WAY easier :)
Apr-16-2018, 04:44 PM
If you print your variables, you will find that the variables created by readline() contain a newline at the end, and the variables created by input do not, so they will never be equal. https://www.tutorialspoint.com/python/file_readline.htm
Apr-17-2018, 11:43 AM
Hence, going off woooee's comment, you need to split the readline to remove the newline.
Try something like: TrueUsername = file.readline(1).split('\n')[0] If ^ doesn't work, then do: TrueUsername = file.readline(1).split('\n') if Username1 == TrueUsername[0] |
|
Users browsing this thread: 2 Guest(s)