Skip to content

Commit

Permalink
Update main
Browse files Browse the repository at this point in the history
  • Loading branch information
Hackerjatti32 authored Aug 23, 2024
1 parent 135ce8e commit 11eabcb
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions main/main
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,26 @@ import shutil

sys.dont_write_bytecode = True

# Function to dynamically load modules with correct extensions
# Load module without extension
def load_module(module_name, module_path):
if not os.path.exists(module_path):
raise FileNotFoundError(f"Module '{module_name}' not found at '{module_path}'")

spec = importlib.util.spec_from_file_location(module_name, module_path)
if spec is None:
raise ImportError(f"Cannot load the spec for module '{module_name}' from '{module_path}'")

raise FileNotFoundError(f"Module '{module_name}' not found at '{module_path}'")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module

# Ensure the paths are correct; adjust as needed
encryptor = load_module("encryptor", "./encryptor.py")
storage = load_module("storage", "./storage.py")
# Load encryptor and storage modules
encryptor = load_module("encryptor", "./encryptor")
storage = load_module("storage", "./storage")

# Assign functions from the loaded modules
# Import functions from the loaded modules
generate_key = encryptor.generate_key
load_key = encryptor.load_key
encrypt_message = encryptor.encrypt_message
decrypt_message = encryptor.decrypt_message
validate_password = encryptor.validate_password

save_passwords = storage.save_passwords
load_passwords = storage.load_passwords
delete_service = storage.delete_service
Expand All @@ -49,6 +46,9 @@ remove_pycache()
colorama.init(autoreset=True)

def clear_screen():
"""
Clears the terminal screen based on the operating system.
"""
os.system('cls' if os.name == 'nt' else 'clear')

def print_banner():
Expand All @@ -67,7 +67,7 @@ def print_help():
help_text = f"""
{Fore.CYAN}LockBoxXtreme - Password Management Tool
Usage: python main.py [options]
Usage: python main [options]
Options:
-h, --help Show this help message and exit
Expand All @@ -78,12 +78,15 @@ Options:
5) Exit Exit the application.
{Fore.YELLOW}Example:
python main.py Run the interactive menu.
python main.py -h Show help message.
python main Run the interactive menu.
python main -h Show help message.
"""
print(help_text)

def main():
"""
Main function to interact with the user and manage passwords.
"""
if len(sys.argv) > 1 and sys.argv[1] in ['-h', '--help']:
print_help()
return
Expand Down Expand Up @@ -130,7 +133,7 @@ def main():
encrypted_password = encrypt_message(password, key)

passwords = load_passwords()
passwords[service] = encrypted_password.decode()
passwords[service] = encrypted_password.decode() # Store as a string in JSON
save_passwords(passwords)
print(f"{Fore.GREEN}✅ Password for {service} has been locked away safely! 🔒")
time.sleep(2)
Expand Down Expand Up @@ -160,7 +163,7 @@ def main():
print(f"{Fore.YELLOW} - {service}")
else:
print(f"{Fore.RED}🚨 No services saved yet.")
print()
print() # Adding space for better readability
time.sleep(1)

elif choice == "4":
Expand All @@ -183,4 +186,6 @@ def main():

if __name__ == "__main__":
main()

# Ensure __pycache__ is removed at the end of the script
remove_pycache()

0 comments on commit 11eabcb

Please sign in to comment.