Dec-05-2019, 02:08 AM
(This post was last modified: Dec-05-2019, 02:08 AM by Justice_py.)
So I'm creating a basic program where when it is run it asks the user if they have an account. If they enter "n" (no) then they are prompted to create a username and password. If they enter "y" they can login. the issue is that the username and password is only stored as key:value while the program is running, and is forgotten as soon as it is exited. If I manually enter into the dictionary a key:value then it is saved as an account and I can login to it. I'm trying to make it so that the account created when the user signs up is automatically put into the dictionary. Here is what I have:
*John:Doe and GEO:Rock are key value's that I put in just to test its ability to save an account.
users = {"John":"Doe", "GEO":"Rock"}
status = ""
def mainDisplay():
status = input("Do you have an account?: y/n? Press ! to quit: ")
if status == "y":
existUser()
elif status == "n":
newUser()
elif status == "!":
quit()
def newUser():
createAccount = input("Please create a username: ")
if createAccount in users:
print("\nUsername already taken.\n")
else:
createPass = input("Create a password")
users[createAccount] = createPass
print("\nUser created\n")
def existUser():
login = input("Enter your username: ")
passw = input("Enter your password: ")
if login in users and users[login] == passw:
print("\nLogin successful.\n")
else:
print("\nError: invalid username or password and/or invalid combination.")
while status != "!":
mainDisplay()Thanks*John:Doe and GEO:Rock are key value's that I put in just to test its ability to save an account.
