title: Python Password Refuses to be Validated
body: <p>My code refuses to validate the entered username and password even when entered correctly.</p>
  
  <p>Code included below; have I gone wrong anywhere? If so, could you please tell me where?</p>
  
  <p>Cheers.</p>
  
  <pre><code>import time
  
  print ("Before playing, you must register.")
  time.sleep(1)
  username = open("username.txt","w+")
  password = open("password.txt","w+")
  
  print ("Please enter your desired username.")
  username_input = input("&gt; ")
  print ("Please enter your desired password.")
  password_input = input("&gt; ")
  
  username.write(username_input)
  password.write(password_input)
  username.close()
  password.close()
  
  time.sleep(1)
  print ("Now, we must authenticate your username and password.")
  time.sleep(0.5)
  print ("Please input your username.")
  u_input = input ('&gt; ')
  print ("Please input your password.")
  p_input = input ('&gt; ')
  username.open("username.txt","r")
  password.open("password.txt","r")
  u_contents = username.read()
  p_contents = password.read()
  if u_input == u_contents:
    print ("Username authenticated.")
  
  if p_input == p_contents:
    print ("Password authenticated.")
  
  else:
    print ("Incorrect username or password.")
  
  username.close()
  password.close()
  </code></pre>