Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why doesn't this work?
#1
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."
Quote
#2
Please put your code in Python code tags, you can find help here.
Quote
#3
There you go.
Quote
#4
you should use configparser.

WAY easier :)
Quote
#5
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
nilamo likes this post
Quote
#6
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]
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  1st Script written doesn't output anything. Need some else's eyes Kym 3 131 Mar-21-2018, 04:19 PM
Last Post: nilamo
  cx-Freeze exe doesn't work ammann 1 82 Mar-19-2018, 10:58 AM
Last Post: buran
  curses.initscr doesn't work zaphod424 3 93 Feb-28-2018, 12:36 PM
Last Post: Gribouillis
  Why doesn't this code work? hsezgin 4 167 Jan-12-2018, 01:44 PM
Last Post: hsezgin
  Multiprocessing doesn't work in this code mraabs 4 224 Dec-24-2017, 07:48 PM
Last Post: mraabs
  How do you check if something exists or doesn't in the conditions of an if? Klar 1 162 Dec-15-2017, 03:47 PM
Last Post: sparkz_alot
  cx_Freeze doesn't seem to work owenwalker65 7 3,659 Dec-07-2017, 02:23 AM
Last Post: issac_n
  Paramter lists when shift+tab doesn't work sobrio1 0 223 Oct-15-2017, 03:41 PM
Last Post: sobrio1
  os.path.exists apparently doesn't always work! Larz60+ 2 471 Oct-10-2017, 10:16 PM
Last Post: sparkz_alot
  speech_to_text command doesn't seem to work snakebyte 10 686 Sep-18-2017, 09:15 PM
Last Post: snakebyte

Forum Jump:


Users browsing this thread: 1 Guest(s)