Hey all,
Is it a good idea to use TKInter to change my password program into a GUI?
I know it needs improvements, and I've noted them below:
[code]
#This is for a password protected program to store passwords.
import getpass password = "hello" # This should instead load a file with the password in it. sitelist = {} def load_file(pw):
import os filename = 'passcard.txt' # Weak, because any text file editor can read the usernames and passwords! if os.path.exists(filename): store = open(filename,'r') for line in store: site = line.strip() ID = store.next().strip() pw[site] = ID else: store = open(filename,'w') # create new empty file store.close() def save_file(pw):
store = open('passcard.txt',"w") for site,ID in sitelist.items(): store.write(site + '\n') store.write(ID + '\n') store.close() def main_menu(): print "1) Add a login info card" print "2) Lookup a login info card" print "3) Remove a login info card" print "4) Print Login info list" print "9) Save and Exit" def add_site():
print "Add a login info card" site = raw_input("Site: ") ID = raw_input("User ID and passcard, seperated by a space: ") # seperated should be spelt separated. sitelist[site] = ID def lookup_site():
print "Lookup a login info card" site = raw_input("Site: ") if sitelist.has_key(site): print site,sitelist[site] else: print site," was not found." def remove_site():
print "Remove a login info card" site = raw_input("Site: ") if sitelist.has_key(site): del sitelist[site] else: print site," was not found." def print_login_info():
print "Login Info" for site in sitelist.keys(): print "Site: ",site," \tID Passcard: ",sitelist[site]+"\n" # There should be a way to change the password, or add it for first
time users.
print "The Password Program" print "By Nathan Pinno" load_file(sitelist) answer = getpass.getpass("What is the password? ") while password != answer: print "The password is incorrect." answer = getpass.getpass("What is the password? ") print "Welcome to the second half of the program."
while 1: main_menu() menu_choice = int(raw_input("Choose an option (1-4, or 9: ")) if menu_choice == 1: add_site() elif menu_choice == 2: lookup_site() elif menu_choice == 3: remove_site() elif menu_choice == 4: print_login_info() elif menu_choice == 9: break else: print "That's not an option!" save_file(sitelist) print "Have a nice day!" [/code] Is it possible to salvage it?
Give me your honest advice.
Nathan Pinno
|
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor