def delete_file(ctx, master_password): """Endpoint to delete a new file.""" try: path = ctx.obj.get('path') salt = FileStorageHelper.get_salt_from_path(path) FileHandler(file_path=path, password=master_password, salt=salt).delete() ok_msg("File successfully deleted.") except FileNotFoundError: err_msg("No such file '{}'".format(ctx.obj.get('path'))) exit() except InvalidToken: err_msg("Wrong password.") exit()
def generate(length, special_chars, no_upper, no_digit, show_password, copy_to_paperclip): """Generate a password. Use the 'conf_passgen.ini' as default.""" info_msg("🔒 Password Generator 🔒") pwg = PasswordGenerator(length=length) pwg.use_digits(no_digit) pwg.use_uppercase(no_upper) pwg.use_special_characters(special_chars) password = pwg.generate() if show_password: click.echo(password) if copy_to_paperclip: pyperclip.copy(password) ok_msg("Password copied in the clipboard 📋")
def new(ctx, master_password): """Endpoint to create a new file.""" try: FileHandler.create_file(file_path=ctx.obj.get('path'), password=master_password) ok_msg("Password file Created 📝") except IsADirectoryError: err_msg('"{}" is a directory.'.format(ctx.obj.get('path'))) exit() except FileExistsError: err_msg("file already exists.") exit() except Exception as e: err_msg(e)
def delete(ctx, name): """Get delete a password in an encrypted file.""" try: path = ctx.obj.get("path") salt = FileStorageHelper.get_salt_from_path(path) fh = FileHandler(file_path=path, password=ctx.obj.get("master_password"), salt=salt) fh.delete_entry(entry_name=name) ok_msg("Deletion successful") exit() except InvalidToken: err_msg("Master password incorrect. Please retry.") exit() except Exception as e: err_msg(e.__str__()) exit()
def add(ctx, name, username, password_): """Get add a new password in an encrypted file.""" try: path = ctx.obj.get("path") salt = FileStorageHelper.get_salt_from_path(path) fh = FileHandler(file_path=path, password=ctx.obj.get("master_password"), salt=salt) fh.add_entry( PasswordEntry(username=username, password=password_, name=name)) ok_msg("Addition of a new password successful") except IndexError as e: err_msg(e) exit() except Exception as e: err_msg(e) exit()
def copy_to_paper_clip(ctx, new_value): """Change the default value of copy_to_paperclip.""" ctx.obj.copy_to_paper_clip = new_value ctx.obj.update_conf(CONF_PATH) ok_msg("Conf updated")
def show_password(ctx, new_value): """Change the default value of show_password.""" ctx.obj.show_password = new_value ctx.obj.update_conf(CONF_PATH) ok_msg("Conf updated")
def length(ctx, new_value): """Change the default value of length.""" ctx.obj.length = new_value ctx.obj.update_conf(CONF_PATH) ok_msg("Conf updated")
def digits(ctx, new_value): """Change the default value of use_digits.""" ctx.obj.use_digits = new_value ctx.obj.update_conf(CONF_PATH) ok_msg("Conf updated")
def spec_char(ctx, new_value): """Change the default value of use_special_chars.""" ctx.obj.use_spec_char = new_value ctx.obj.update_conf(CONF_PATH) ok_msg("Conf updated")
def uppercase(ctx, new_value): """Change the default value of use_uppercase.""" ctx.obj.use_uppercase = new_value ctx.obj.update_conf(CONF_PATH) ok_msg("Conf updated")