Jun-26-2020, 09:46 AM
(This post was last modified: Jun-26-2020, 09:47 AM by blacklight.)
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!")
