I am creating a login script and I store the usernames and passwords in a dictionary. The problem is though, when I open it a second time it doesn't store the users that have already been registered. I know this is normal but is there a way to get round that? Perhaps using a file?
Here is my EDITED code:
import os
import sys
users={}
status=""
def login():
status=raw_input("Are you a new user?")
if status=="y"
createnewuser=raw_input("Create username: ")
if createnewuser in users:
print "User already exists!"
else createpsswrd=raw_input("Create new password")
users[createnewuser]=createpsswrd
print "Register successful!"
elif status == "n":
login=raw_input("Username: ")
passw=raw_input("Password: ")
if login in users and users[login]==passw:
print "Login successful!"
os.system("python file.py")
return
else:
print "Username and password do not match."
try:
with open('file') as infile:
cPickle.load(infile)
except:
users = {}
while status != "q":
login()
with open('file') as outfile:
cPickle.dump(users, outfile)
Edited results: I get through the entire script with no errors but the outfile file has nothing written on it. The dictionary still doesn't save across sessions so nothing has changed. I have changed all my sys.exit()'s to returns as well. I am using Raspian on a raspberry Pi 2 if that matters.
EDIT 2
Answered by me below :)