Skip to content

Instantly share code, notes, and snippets.

@mhornbacher
Created April 19, 2017 16:03
Show Gist options
  • Save mhornbacher/51ba41c6235d4cd0d2d277ca9fdf44cf to your computer and use it in GitHub Desktop.
Save mhornbacher/51ba41c6235d4cd0d2d277ca9fdf44cf to your computer and use it in GitHub Desktop.
A basic python script for managing username password combos
import pickle, os.path, sys
filename = "Accounts.picklefile"
if os.path.isfile(filename):
fileload = open(filename, 'rb')
try:
database = pickle.load(fileload)
except EOFError:
print("Error reading file")
database = []
fileload.close()
else:
print("No Data Found... creating new array")
database = []
run = True
def save():
print("Saving data...")
fileout = open(filename, 'wb')
pickle.dump(database, fileout)
fileout.close()
print("Data saved")
def add_account():
username = input("UserName: ")
password = input("Password: ")
account = [username, password]
database.append(account)
save()
def remove_account():
show_accounts()
index = (int)(input("Enter an index: "))
try:
database.pop(index-1)
save()
except IndexError:
print("Not a valid index")
def show_accounts():
index = 1
print("i: username \t password")
for account in database:
print("{}: {} \t{}".format(str(index), account[0], account[1]))
index += 1
while run == True:
command = input("Enter command: (add/remove/view/exit) ").lower()
if command == 'add':
add_account()
elif command == 'remove':
remove_account()
elif command == 'view':
show_accounts()
elif command =='exit':
print("Terminating application")
run = False
else:
print("Invalid Command: {}".format(command))
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment