Question: Need Python program to remember passwords I have the following program that takes user input and create a dataframe. It remembers the previous usernames every

Need Python program to remember passwords

I have the following program that takes user input and create a dataframe. It remembers the previous usernames every time it is run, which is what I want. The issue is that it is not remembering the passwords, instead overwriting them with the previous usernames.

How can I modify this program so that it remembers the previous usernames AND passwords?

Here is my program:

import pandas as pd from datetime import datetime

usernames = []

def myFunc(): passwords = [] # list to store passwords

with open("userf", "r+") as f: # use "w" mode instead of "r+" for line in f: usernames.append(line.strip()) passwords.append(line.strip()) # store password in the same index as the username

while True: username = input("Enter your username: ").lower().strip() if username not in usernames: usernames.append(username) f.write(username + " ") password = input("Enter a password: ") passwords.append(password) # store password in the same index as the username

else: print("username already exists, try again") continue while True: ans = input("Add another user? Y/N ").lower().strip() if ans not in ['yes', 'y', 'no', 'n']: print("Please answer y ") else: break if ans == "yes" or ans == "y": continue else: break

user_dictionary = { "Username": usernames, "Password": passwords }

mydb = pd.DataFrame(user_dictionary) print(mydb) mydb.to_json("database.json")

try: with open("database.json") as saveddb: database = pd.read_json(saveddb) except FileNotFoundError: myFunc() else: print(database) myFunc()

Need Python program to remember passwords I have the following program that

Shown below is the issue I have when running the program and trying to add a new user (first time executing):

takes user input and create a dataframe. It remembers the previous usernames

It works fine the first time it is run, shown above, because it remembers the password.

Second time executing:

every time it is run, which is what I want. The issue

...But when another user is added on second execution, it overwrites the previous passwords with the username. I need it to remember the previous passwords when new users are added on subsequent executions.

Please help!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!