Python Forum
How do I store the data in another txt file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I store the data in another txt file
#1
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!")
Reply
#2
you should use getpass, to keep secret see: https://pymotw.com/3/getpass/
there is a bit on how to pipe to a file.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Store variable data and display sum after 60 seconds the_dude 11 3,443 Dec-16-2021, 07:07 PM
Last Post: deanhystad
  xml file creation from an XML file template and data from an excel file naji_python 1 2,097 Dec-21-2020, 03:24 PM
Last Post: Gribouillis
  how do i store then call a mp3 from sqlite3 .db file gr3yali3n 3 5,717 Dec-11-2020, 10:28 AM
Last Post: snippsat
  Regex text file to store data in list TheSithSiggi 1 1,517 Dec-03-2020, 04:46 PM
Last Post: bowlofred
  How to save CSV file data into the Azure Data Lake Storage Gen2 table? Mangesh121 0 2,102 Jun-26-2020, 11:59 AM
Last Post: Mangesh121
  ChatterBot: How to store unanswered question in a text file? animrehrm 0 1,907 May-16-2020, 06:00 AM
Last Post: animrehrm
  Read csv file, parse data, and store in a dictionary markellefultz20 4 4,562 Nov-26-2019, 03:33 PM
Last Post: DeaD_EyE
  Reading blob data from database by python and store it in .zip format Adityasi 2 6,592 Nov-18-2019, 05:22 PM
Last Post: ibreeden
  a contact book - a class made to store data apollo 2 1,945 Jun-12-2019, 04:33 PM
Last Post: apollo
  I can't use file __init__ to store shared variables and classes in the package AlekseyPython 2 3,327 Feb-04-2019, 06:26 AM
Last Post: AlekseyPython

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020