-1

I am currently creating a signup and login page for an application but whenever I create a new username/password combo, I see it in my list right after creating it (I print the dictionary at the end of the program so I can see it) but after I decide to rerun the code, the usernames and passwords that I just created are gone. How do I get these to stay even after rerunning the code?

I do not know if adding my code will help here (I do not think that it will) but I will add the bits that I feel could potentially be the most helpful:

import re

usernames_passwords = {'lmaoidontknow': 'password123',
                   'evillover456': 'waterworld332',
                   'xyzitsme': 'notmypass',
                   'unicornpops': 'blahbleh76'}

while not chosen_user:
        chosen_user = input("""Enter the username that you would like. Please keep it between 6 and 15 
        characters. Do not use special characters such as '&', '@', or '!' in your username. Underscores are 
        allowed.\n>""")
        if (6 <= len(chosen_user) <= 15) and re.search(r"^[a-zA-Z0-9_]+$", chosen_user):
            print('')
        else:
            print('Username does not meet the requirements. Please try again.')
            chosen_user = False
        if chosen_user in input_usernames:
            print('This username is already taken. PLease try again.')
            chosen_user = False

The dictionary at the top was created just to test certain things such as making sure usernames were not replicated and they are not permanent. Whenever I rerun my code, that dictionary is the only usernames/passwords that remain and I want all usernames and passwords that I input to stay.

Edit: This is only the username code. Password code can be included if asked for but I do not think it will make much of a difference.

2 Answers2

0

When you use a hardcoded dictionary , its data would not persist when you rerun server , you need to use db to store and make them persisitent.

Naman Agarwal
  • 96
  • 1
  • 7
0

Why dont you store the chosen_user to your usernames_passwords? Let's say:

if (6 <= len(chosen_user) <= 15) and re.search(r"^[a-zA-Z0-9_]+$", chosen_user):
    pass_word = input("Enter your password: ")
else:
    print('Username does not meet the requirements. Please try again.')
    chosen_user = False
    continue
if chosen_user in input_usernames:
    print('This username is already taken. PLease try again.')
    chosen_user = False
    continue
else:
    usernames_passwords[chosen_user] = pass_word

But I highly recommend that you should store your username and password in database to access them, or you could store to a file with password is encrypted

Binh
  • 1,143
  • 6
  • 8
  • This still doesn't satisfy the persistence requirement. The next time the script is run, the updated dict from the previous time is gone. – Arya McCarthy Apr 04 '20 at 04:33