Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!C:\Python34\python.exe
- import base64
- import os.path
- pass_file = 'pass_file.txt'
- keys_file = 'keys_file.txt'
- organized_keys = []
- def option_chosen(option, key_name):
- if option == 1:
- key_pass = ''
- while(key_pass == ''):
- key_pass = input('Enter the password of the key: ')
- organized_keys.append([key_name, key_pass])
- print('Added successfully!')
- elif option == 2:
- if key_name == 'all':
- print('Key name\tKey Password')
- for z in range(0, len(organized_keys)):
- print(organized_keys[z][0], '\t\t',
- organized_keys[z][1])
- else:
- found = False
- for z in range(0, len(organized_keys)):
- if organized_keys[z][0] == key_name:
- print('Key name\tKey Password')
- print(organized_keys[z][0], '\t\t',
- organized_keys[z][1])
- found = True
- break
- if found is False:
- print('Key name not found!')
- elif option == 3:
- found = False
- for z in range(0, len(organized_keys)):
- if organized_keys[z][0] == key_name:
- found = True
- print(organized_keys[z][0], '\t\t',
- organized_keys[z][1])
- repeat = True
- while repeat != False:
- toedit = input('Edit name or key?: ')
- tmpvalue = ''
- if toedit == 'name':
- while not len(tmpvalue):
- tmpvalue = input('Write the new name: ')
- repeat = False
- organized_keys[z][0] = tmpvalue
- elif toedit == 'key':
- while len(tmpvalue) == 0:
- tmpvalue = input('Write the new key: ')
- repeat = False
- organized_keys[z][1] = tmpvalue
- else:
- repeat = True
- print('Changed successfully!')
- break
- if found is False:
- print('Key name not found!')
- elif option == 4:
- all_found = []
- for z in range(0, len(organized_keys)):
- if organized_keys[z][0] == key_name:
- all_found.append(z)
- if len(all_found) == 1:
- organized_keys.pop(all_found[0])
- print('Deleted successfully!')
- elif not len(all_found):
- print('Key name not found!')
- else:
- print('This key was found more than on time!')
- yes = input('Delete all? (yes/no)')
- if yes == 'yes' or 'y':
- count = 0
- for x in range(0, len(all_found)):
- organized_keys.pop(all_found[x]-count)
- count += 1
- print('All deleted successfully!')
- elif option == 5:
- finalized = ''
- for z in range(0, len(organized_keys)):
- finalized += organized_keys[z][0]+':'+\
- organized_keys[z][1]+'\n'
- file = open(keys_file,'wb')
- file.write(base64.b85encode(finalized.encode()))
- file.close()
- print('Saved successfully!')
- return
- def login():
- if os.path.exists(pass_file) is True:
- file = open(pass_file,'rb')
- tmppass = base64.b85decode(file.read())
- file.close()
- password = ''
- while(password.encode() != tmppass):
- password = input('Write your password: ')
- else:
- reset = True
- password = ''
- while reset != False:
- print('You don\'t have a password!\n')
- password = input('Write your password: ')
- cpassword = input('Please, confirm your password: ')
- while(password != cpassword):
- print('If you want to reset, write \'reset\'')
- cpassword = input('Wrong password!\nPlease, confirm your password: ')
- if(cpassword == 'reset'):
- reset = True
- break
- if(cpassword != 'reset'):
- reset = False
- file = open(pass_file,'wb')
- file.write(base64.b85encode(password.encode()))
- file.close()
- return
- def loadkeys():
- if os.path.exists(keys_file) is False:
- file = open(keys_file,'w')
- file.close()
- file = open(keys_file,'rb')
- tmpkeys = file.read()
- file.close()
- encoded = base64.b85decode(tmpkeys)
- tmpkeys = encoded.decode().splitlines()
- for x in range(0,len(tmpkeys)):
- organized_keys.append(tmpkeys[x].split(':'))
- return
- def programe():
- login()
- print('Login done!')
- loadkeys()
- print('Load finished!')
- while True:
- print('\n\nChoose an option:\n' +\
- '1 - add a key\n' +\
- '2 - see a key\n' +\
- '3 - edit a key\n' +\
- '4 - delete a key\n' +\
- '5 - save file\n' +\
- '6 - finish program\n\n')
- option = int(input('Your option: '))
- if option == 6:
- break
- elif option == 1:
- key_name = input('Enter the name of the key: ')
- option_chosen(option, key_name)
- elif option == 5:
- option_chosen(option, '')
- elif option > 1 and option < 5:
- if not len(organized_keys):
- print('You don\'t have keys')
- else:
- key_name = '';
- input_msg = 'Key name' +\
- ((' ',' (use \'all\' fro all)')[option == 2]) +': '
- key_name = input(input_msg)
- option_chosen(option, key_name)
- else:
- print('Invalid option!')
- return
- programe()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement