πŸ” VaultBox – Lock/Unlock Any File in 1 Click with Python GUI | FuzzuTech

Demo :


Click Video πŸ‘‡πŸ‘‡πŸ‘‡































Features:

  • Instant file encryption & decryption

  • Auto log tracking

  • Beginner-friendly CustomTkinter UI

  • Works offline

  • 100% open source


Code :


import customtkinter as ctk

from tkinter import filedialog

import os, json

from cryptography.fernet import Fernet

from datetime import datetime


ctk.set_appearance_mode("dark")

ctk.set_default_color_theme("blue")


KEY_FILE = "vault.key"

LOG_FILE = "access_log.json"


# Generate key if not exists

if not os.path.exists(KEY_FILE):

    with open(KEY_FILE, "wb") as f:

        f.write(Fernet.generate_key())


with open(KEY_FILE, "rb") as f:

    key = f.read()

fernet = Fernet(key)


if not os.path.exists(LOG_FILE):

    with open(LOG_FILE, "w") as f:

        json.dump([], f)


class VaultBox(ctk.CTk):

    def __init__(self):

        super().__init__()

        self.title("πŸ”’ VaultBox - File Locker")

        self.geometry("400x500")

        self.resizable(False, False)


        ctk.CTkLabel(self, text="VaultBox", font=("Arial", 24, "bold")).pack(pady=20)

        self.status_label = ctk.CTkLabel(self, text="Select a file to lock or unlock.")

        self.status_label.pack(pady=10)


        ctk.CTkButton(self, text="πŸ” Lock File", command=self.lock_file).pack(pady=10)

        ctk.CTkButton(self, text="πŸ”“ Unlock File", command=self.unlock_file).pack(pady=10)

        ctk.CTkButton(self, text="πŸ“œ View Access Log", command=self.view_logs).pack(pady=20)


    def log_action(self, file, action):

        with open(LOG_FILE, "r") as f:

            logs = json.load(f)


        logs.append({

            "file": os.path.basename(file),

            "action": action,

            "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        })


        with open(LOG_FILE, "w") as f:

            json.dump(logs, f, indent=4)


    def lock_file(self):

        file = filedialog.askopenfilename()

        if file:

            with open(file, "rb") as f:

                data = f.read()


            encrypted = fernet.encrypt(data)

            with open(file + ".locked", "wb") as f:

                f.write(encrypted)


            os.remove(file)

            self.status_label.configure(text=f"πŸ” File Locked: {os.path.basename(file)}")

            self.log_action(file, "Locked")


    def unlock_file(self):

        file = filedialog.askopenfilename(filetypes=[("Locked Files", "*.locked")])

        if file:

            with open(file, "rb") as f:

                encrypted = f.read()


            try:

                decrypted = fernet.decrypt(encrypted)

                orig_name = file.replace(".locked", "")

                with open(orig_name, "wb") as f:

                    f.write(decrypted)

                os.remove(file)

                self.status_label.configure(text=f"πŸ”“ File Unlocked: {os.path.basename(orig_name)}")

                self.log_action(file, "Unlocked")

            except:

                self.status_label.configure(text="❌ Invalid key or file error!")


    def view_logs(self):

        top = ctk.CTkToplevel(self)

        top.title("πŸ“œ Access Log")

        top.geometry("300x400")


        with open(LOG_FILE, "r") as f:

            logs = json.load(f)


        for entry in reversed(logs[-10:]):

            ctk.CTkLabel(top, text=f"{entry['timestamp']} - {entry['action']}: {entry['file']}").pack(pady=2)


if __name__ == "__main__":

    app = VaultBox()

    app.mainloop()

Comments

Popular posts from this blog

πŸš€ Simple Login & Registration System in Python Tkinter πŸ“±

πŸš€ Create a Python Screen Recorder with Audio (Complete Code)

Python IP Tracker App with GUI | Track IP Location Real-Time! (Working Project)