Note: I asked this on Stackoverflow and got no answer so i am re asking. That is why I am trying to use Pickle.
Here is my code:
Expand|Select|Wrap|Line Numbers
- 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)