![]() |
How do I store the data in another txt file - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How do I store the data in another txt file (/thread-27900.html) |
How do I store the data in another txt file - blacklight - Jun-26-2020 Hi I'm trying to figure out how I can use a txt files for my users and passwords. I have a function that let's you create a new user, however I want that new user to be put in a txt file, so when you login the programm checks if the username and password are in the txt file's list. How do I go about doing this? # making a login system. #ask account prompt/function. ask_account = input("Do you have an account? ") #class to create new users class users: def __init__(self, username, password): self.username = username self.password = password # This is the user list. user_list = [ users("Sem", "ben8"), users("Soar", "ben7") ] # continuing function to access your account if ask_account == "yes": username_ = input("What is your username: ") password = input("What is your password: ") for element in user_list: if username_ == element.username and password == element.password: print("Welcome {}".format(element.username) +"." + "You are logged in!") elif username_ != element.username or password != element.password: print("Invalid username or password!") # continuing function to create a new account and access your new account if ask_account == "no": user_list.append(users(input("insert username: "), input("insert password "))) print("You have created a new account!") username_ = input("What is your username: ") password = input("What is your password: ") for x in user_list: if username_ == x.username and password == x.password: print("Welcome {}".format(x.username) +"." + "You are logged in!") elif username_ != x.username or password != x.password: print("Invalid username or password!") RE: How do I store the data in another txt file - Larz60+ - Jun-26-2020 you should use getpass, to keep secret see: https://pymotw.com/3/getpass/ there is a bit on how to pipe to a file. |