This is my python password system using pickle. It's bad, I know, but it's my first time with pickle.
import pickle
import os
userlist = {'user1':'userpass1', 'user2':'userpass2'}
users = open ("users.pkl", 'wb')
pickle.dump (userlist, users)
username = input ("Enter your username: ")
password = input ("Enter your password: ")
if (username in userlist) and (password == userlist[username]):
print ("Access Granted")
else:
newaccount = input ("User not found. Shall I create a new account? ")
if newaccount == "yes":
username = input ("Please enter your username: ")
password = input ("Please enter yout password: ")
userlist.update({username:password})
pickle.dump (userlist, users)
users.close()
My problem is that, whenever I go to add a new account, using this part:
newaccount = input ("User not found. Shall I create a new account? ")
if newaccount == "yes":
username = input ("Please enter your username: ")
password = input ("Please enter yout password: ")
userlist.update({username:password})
pickle.dump (userlist, users)
users.close()
It seems to add it (and it looks like it's there in the pickle file using notepad) but, I restart the python file, and it does not see it.
I believe it is something to do with this part:
userlist = {'user1':'userpass1', 'user2':'userpass2'}
users = open ("users.pkl", 'wb')
pickle.dump (userlist, users)
Any help is appreciated! :D