#!/usr/bin/env python #Ethan Thompson #Platt Tech Information Technology from os import system #from os module import system import time # import time module import random #import random import json # importing the json module to manipulate files from string import ascii_letters, digits #importing this allows me to get all ascii characters, that are uppercase and/or lowercase loaded = open('Manager.json','r') # loaded being equal to a file and 'r' means to read it my_data = loaded.read()# loaded.read() will allow me to read the file, that being equal to a variable will allow me to do the following loaded.close() CDA = json.loads(my_data) #json.loads is used to parse a valid json string and convert it into the python dictionary json.loads( ) - #inside the parameter I have put my_data which equals loaded.read() so it can take the string from the file and all of that equals converted data which I use all- #over my program. def Main(): print('') print('Main Page') # my main page print('1. Start Generating Password')#pressing 1 activates this program print('2. View a single password')#pressing 2 views all passwords print('3. Delete a password')#press 3 then you can delete a password print('x. Exit Main Page')#exiting the main if you press x Pass_Output = input("START PROGRAM HERE ->>: ")#allowing you to press spacebar to start the program Pass_Items = ['1','2','3','x','', ] # the print statement will activate by pressing 1 ,2 and x ->> these are converted to string to python knows to activate the statements if Pass_Output not in Pass_Items: #if your number isnt in the list named Pass_Items then menu() function will restart to main page Main()#restarts function if Pass_Output == '1':#if you press 1 Gen()#call this function if Pass_Output == '2':#if you press 2 Single()#call this gunction if Pass_Output == '3':#if you press 3 DelPass()#call this function if Pass_Output == 'x':#this is the exit if statement Quit = input('exit? y or n?')#this gives the option to type in a lower/uppercase Y,y or n,N. if Quit == 'y':#if your answer is y quit()#if you want to quit then quit() will stop the program and exit out if Quit == 'n':#if your answer is n system('clear')#clear screen Main()#allows you to start over if Quit == '':#if you press enter by mistake system('clear')#clear screen Main()#go back to the top of the code if Pass_Output != Pass_Items:#if your number not equal to the items in Pass_Items do the following system('clear') #clear screen Main()#lastly restart the code def Gen():#defining by Gen Function try:#I am trying out the code below V = input('before we start, what is your password for?: ')# v will be my variable and name to the head of your password print(V ,' good choice')#this print statement will tell you your answer and say it's a good choice time.sleep(2)#allows python to sleep system('clear')#clears screen C = int(input('give a number from 8-12 for your password: '))#this will give the person a choice between a number from 8 to 12 #I used int(input()) to convert any string into a number so the following code below can work if C in range(8,257):#if the number you inputed thats converted into a number is in range of 8 to 256 do the following Collection = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUZWXYZ1234567890!@#$%^&*~`;:+=_-><,?/\|{}[]' QW = ''.join(random.sample(Collection,C))#form a random collection of letters that has a length of 8, The original code had 5 lines of seperate code for each length print('your password is',QW)#print out the password python generated else:#otherwise print('no password, characters has to be a number from 8 to 12')# print you wont get a password and tells you the proper lengths system('clear')#clears screen Main()#goes all the way to the top of the code to restart time.sleep(2)#allows python to sleep for 2 seconds ask = input("would you like to save your password/back up password?: ") #the variable ask will allow you to input a choice of yes or no except ValueError:#except handle this error you get if you dont input a number, which is known as a value error system('clear')#clears screen Main()#goes to the top of the code, restarts to main page if ask == 'y':#if your input is y then do the following Starting_time = time.strftime("%m/%d/%y, %H:%M:%S")#this should print -->>> the time, #the month/day/year, hours/minutes/seconds print("You have backed up the Manager at: {}".format(Starting_time))#Starting_time is equal to all of the %'s and .format will join those %'s together in the form of n/n/n/ n/n/n print('the password {} is now saved'.format(QW)) #this prints out the term you choose from the dictionary print('{0} password is under the name of {1}'.format(QW,V))# the numbers in the {} are indexes to make sure I format correctly CDA[V] = QW #names the front of dictionary time.sleep(2)#allows python to sleep for 2 seconds write_file()#write file, this allows python to save this to the memory #print('press enter to return to menu')#press enter to do this line of code system('clear')#clears screen Main()#goes to the top of the Main() function if ask == 'backup': file_string = open('copy mynewfile.txt Manager.json','x') #creates your new backed up file print('creating a new manager {}'.format(file_string)) # this creates a new dictionary and it tells that it is creating a new dictionary if ask == 'n':#if you enter n then do the following system('clear')#clear screen Main()#goes to the top of the Main() function def Single(): #Single Function does the following works print("\nhere you will view a specific password")#tells you that you can view a specific password for i in CDA:#for all the items in CDA then print(i)#print out all the items in CDA ViewSingle = input("enter an application from above: ")# Enter an application you see from above system('clear')#clears screen try:#try the following code below print("your password for {} is ->> \n\n {} ".format(ViewSingle,CDA[ViewSingle]))#prints out the Application you inputed and formats it into the Password Manager input("press the enter button to return to menu")#this line allows you to press enter by you inputing enter system('clear')#clears screen Main()#goes to the top of the Main() function except:#except handle all of the errors python faces print('{} this Application is not in your manager'.format(ViewSingle))# tells you that the application that you inputed is not in your manager #if you enter the wrong application then it will tell you input('press enter to try again')#this line of code tells you to press #enter to try again system('clear')#clears screen Main()#goes to the top of the Main() function def write_file():#write file allows me to save the key and values to the memory #if input():# if you input something then loaded = json.dumps(CDA, indent = 4)#indent my Manager.json file and indent each line in the dictionary by 4 toFile = open('Manager.json','w')#Then write in the Manager file toFile.write(loaded)#this will allow me to have the privellege to instead of read but write in the file toFile.close()# toFile.close() allows you to closes the file return#returns this if statement #input("press enter to return to menu")#press enter to go again #return#returns the write_file() function, gives back def DelPass():#This Delete System allows you to delete the application plus the password for it system('clear')#clears screen for i in CDA:#for all the items in CDA then print(i)#print all of it out Removed = input('enter the application to the password you want to remove: ') #Removed is a variable that will allow you to pick the application you want to get rid of system('clear')#clears screen try:#try the following code del CDA[Removed]#del is short for delete, delete CDA[ ->> the application you inputed] write_file()#write file saves the data in which you have deleted a application along with it's password print("deleted the application: {}".format(Removed))#if true then the application will be gone time.sleep(2)#allows python to sleep for 2 seconds system('clear')#clears screen Main()#goes to the Main function by calling out the function with () except:#except handle all of the errors try1 = input('this is not in your manager, would you like to restart?: ')#if your input is not shown then this line above gives the option to restart by using input() if try1 == 'y':#if what you inputted is y then print('going back')#go back to where you starte to deleting the password time.sleep(2)#allows python to sleep for 2 seconds DelPass()#goes back to the DelPass Function to restart if try1 == 'n':#if your input is n then do the following system('clear')#clears screen Main()#goes all the way to the Top of the Function if __name__ == '__main__':#this piece of code allows all of the functions to be activated Main()#this allows me to Activate the Main Function to allow all the code to work