My program is a basic username password system I am working on. It allows you to store a username and password in a pickle file, and then log in with it. However, only the first "account" I make in the file works. I have looked at similar problems, but none of the solutions appear to work. Is there anything I am doing wrong, or need to add so all the accounts work? I have decoded the pickle file and all the accounts are there. I am a beginner programmer, so please give a simple explanation. Here is my code:
import pickle
import sys
l=0
answer="."
c=0
while c==0:
if not answer=="y" or not answer=="yes" or not answer=="Yes" or not answer=="n" or not answer=="No" or not answer=="no":
answer=input("have you already created an account?(y/n)")
if answer=="n" or answer=="no" or answer=="No" or answer=="y" or answer=="yes" or answer=="Yes":
c=1
if answer=="n" or answer=="no" or answer=="No":
p=1
while p==1:
UsernameSet=input("What will your username be? ")
fh = open("list.pkl", 'rb')
try:
Usernameport = pickle.load(fh)
except EOFError:
Usernameport = "."
if not (UsernameSet in Usernameport):
p=2
fh.close()
j=1
while j==1:
PasswordSet=input("What will your password be? ")
fh = open("list.pkl", 'rb')
try:
Passwordport = pickle.load(fh)
except EOFError:
Passwordport = "."
if not (PasswordSet in Passwordport):
if PasswordSet == UsernameSet:
print("Your username and password cannot be the same")
else:
j=2
print("You have created an account. please reload")
fh.close()
importthing = (UsernameSet,PasswordSet)
fh = open("list.pkl", 'ab')
pickle.dump(importthing, fh)
fh.close()
if answer=="y" or answer=="yes" or answer=="Yes":
p=1
while p==1:
Usernamething=input("Username: ")
fh = open("list.pkl", 'rb')
Usernamestuff = pickle.load(fh)
if (Usernamething in Usernamestuff):
p=2
l=Usernamething
fh.close()
j=1
while j==1:
Passwordthing=input("Password: ")
fh = open("list.pkl", 'rb')
Passwordstuff = pickle.load(fh)
if (Passwordthing in Passwordstuff):
j=2
print("you have logged in")
sys.exit()
fh.close()