I am very new to python and could use a little help, I created a password locker program to store and recall accounts, logins and passwords for various accounts which requires 1 password to view all the stored info. this is my first program involving the pickle module and could use some input on how to increase my efficiency in using it, also is there a way to increase the encryption of the stored info so words can't be seen in the pickle file. Thanks!
here is what I have going on.
#! python3
import sys
import pickle
PIK = "pickle.pkl"
account = []
login = []
password = []
print('What is your password?')
while True:
p = input()
if p == 'springtime':
break
else:
print('Incorrect password')
continue
while True:
try:
with open(PIK, 'rb') as f:
f.close()
break
except FileNotFoundError:
with open(PIK, 'ab') as f:
pickle.dump(account, f)
pickle.dump(login, f)
pickle.dump(password, f)
f.close()
break
with open(PIK, 'rb') as f:
while True:
try:
account = pickle.load(f)
login = pickle.load(f)
password = pickle.load(f)
except EOFError:
break
def add():
while True:
print('What type of account is this? CANCEL to menu')
y = input()
if y.lower() == 'cancel':
menu()
break
elif y.lower() != 'cancel':
print('Are you sure this is the account type?(y/n): ' + y)
confirm = input()
if confirm.lower() == 'y':
account.append(y)
break
else:
continue
while True:
print('What is the login for the account? CANCEL to menu')
x = input()
if x.lower() == 'cancel':
menu()
break
elif x.lower() != 'cancel':
print('Are you sure this is the login?(y/n): ' + x)
confirm = input()
if confirm.lower() == 'y':
login.append(x)
break
else:
continue
while True:
print('What is the password for the account? CANCEL to menu')
z = input()
if z.lower() == 'cancel':
menu()
elif x.lower != 'cancel':
print('Are you sure this is the password?(y/n): ' + z)
confirm = input()
if confirm.lower() == 'y':
password.append(z)
print('Would you like to create another account?(y/n)')
answer = input()
if answer.lower() == 'y':
add()
break
elif answer.lower() == 'n':
with open(PIK, 'ab') as f:
pickle.dump(account, f)
pickle.dump(login, f)
pickle.dump(password, f)
f.close()
menu()
break
elif confirm.lower() == 'n':
menu()
break
def delete():
snap()
print('What account would you like to delete? (1-100) CANCEL to menu')
selection = input()
if selection.lower() == 'cancel':
menu()
else:
try:
result = int(selection)-1
del account[result]
del login[result]
del password[result]
with open(PIK, 'ab') as f:
pickle.dump(account, f)
pickle.dump(login, f)
pickle.dump(password, f)
f.close()
except IndexError:
print('account does not exist, try again')
delete()
except ValueError:
print('Please select account # or CANCEL')
delete()
print('Would you like to delete another account?(y/n)')
d = input()
if d.lower() == 'y':
delete()
elif d.lower() == 'n':
menu()
def view():
snap()
menu()
def menu():
print('Would you like to DELETE, ADD, or VIEW an account? (enter to EXIT)')
d = input()
if d.lower() == 'delete':
delete()
elif d.lower() == 'add':
add()
elif d.lower() == 'view':
view()
elif d == '':
exit()
else:
menu()
def snap():
for i in range(len(account)):
print('\n*******', i+1, '*******\nACCOUNT: ', account[i], '\nLOGIN: ', login[i], '\nPASSWORD: ', password[i], '\n')
menu()