0

I want to add an error message after every incorrect log in.

def login():
    Username='' 
    Password=''
    counter=0
    for line in open("Credentials.txt","r").readlines(): # Read the lines
        login_info = line.split() # Split on the space, and store the results in a list of two strings
        while Username != login_info[0] and Password != login_info[1]: #If the username and password do not match the string elements from the txt file, starts the loop 
            while not (Username == login_info[0] and Password == login_info[1]):
                Username = input("Please enter your username: " ) #get elements from the user
                Password = input("Please enter your password: ")
            print("welcome")
        break

login() # call the function
somesingsomsing
  • 3,182
  • 4
  • 29
  • 46
  • You can just `print` to `stderr` no ? (refer to [this](https://stackoverflow.com/questions/5574702/how-to-print-to-stderr-in-python)) or you can use a logging module (there's plenty of it, search for it and you'll find what you want) – Nenri Apr 05 '19 at 14:22
  • You can use `error handling techniques` available in python like https://docs.python.org/3/tutorial/errors.html – CodeIt Apr 05 '19 at 14:24
  • and yeah, as ^ , the `try except` blocks – Nenri Apr 05 '19 at 14:25

0 Answers0