Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sys import *
- from pathlib import Path
- from os import stat
- def view():
- contents = ''
- try:
- if stat('logins.gco').st_size > 0:
- file = open("logins.gco", "r")
- contents = file.read()
- file.close()
- else:
- print('File is empty.')
- contents = None
- except Exception as e:
- print('There is no file currently saved.')
- print('Would you like to create a file to save to? (y/n)')
- make_file = input('> ').lower()
- if make_file == 'y':
- file = open('logins.gco', 'w')
- if stat('logins.gco').st_size == 0:
- print('A new file was created!')
- print('No logins to view!')
- else:
- print('No file was created!')
- print('To view saved longins, please add a login.')
- return contents
- def add(name, password):
- user_name = name
- user_password = password
- file = open("logins.gco", "a")
- file.write(f'{user_name}:{user_password}\n')
- file.close()
- key_file = Path('master.gco')
- master_key = ''
- if key_file.exists():
- file = open('master.gco', 'r')
- master_key = file.readline()
- file.close()
- else:
- print('A master key does not seem to exist for this program.\n Please enter one:')
- master_key = input('> ')
- file = open('master.gco', 'w')
- file.write(master_key)
- file.close()
- print("Welcome! Please enter your master key to continue:")
- check_key = input('> ')
- quit_program = False
- while not quit_program:
- if check_key == master_key and quit_program == False:
- print(f'''What would you like to do?
- View - view saved logins
- Add - add a new login
- Quit - exit program
- ''')
- while True:
- mode = input('> ').lower()
- if mode == 'view':
- saved_logins = view()
- print(saved_logins)
- elif mode == 'add':
- user_name = input('Username: ')
- user_password = input('Password: ')
- add(user_name, user_password)
- elif mode =='quit':
- quit_program = True
- break
- else:
- print(f'The command {mode} is not recognized')
- continue
- elif check_key == master_key and quit_program == True:
- break
- else:
- print(f'Sorry, but the password {check_password} is invalid, please try again!')
- #end of app.py
Add Comment
Please, Sign In to add comment