title: Checking a username and password from a text file
body: <p>I'm trying to create an authenticator with python to add into another project.</p>
  
  <p>Here is my code:</p>
  
  <pre><code># User authentication
  global authenticated
  
  def checkAuth():
      global authenticated
      authenticated = False
      # User enters their username and password
      username = input("Enter your username: ")
      password = input("Enter your password: ")
      username = username.strip()
      password = password.strip()
  
      for line in open("users.txt","r").readlines():
          line = line.strip()
          loginInfo = line.split(",")
          print(loginInfo)
          if username == loginInfo[0] and password == loginInfo[1]:
              print("Authorised")
              authenticated = True
  
  isAuth = checkAuth()
  
  if (isAuth):
      input("Authorised \t Press any key to continue: ")
  else:
      input("no auth")
  </code></pre>
  
  <p>When I run my code and enter a correct username and password the if statement inside the checkAuth function evaluated to true, but the if statement at the bottom doesn't get the True value.</p>
  
  <p>These are the two username and password combos in the users.txt file.</p>
  
  <p><a href="https://i.stack.imgur.com/GFaaF.png" rel="nofollow noreferrer">users.txt file</a></p>