Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
Password Manager App Using Python

Password Manager App Using Python

Posted on December 26, 2024December 27, 2024 By Updategadh No Comments on Password Manager App Using Python

Password Manager App Using Python

Step 1: Import Necessary Libraries

  • Import libraries for cryptographic functions, file handling, and GUI creation:
    import hashlib
    from base64 import b64encode, b64decode
    import os
    from Cryptodome.Cipher import AES
    from Cryptodome.Random import get_random_bytes
    import json
    import tkinter as tk
    from tkinter import filedialog, messagebox
    

Step 2: Define Encryption Function

  • Create a function encrypt to:
    1. Generate a random salt.
    2. Derive a secure private key from the password and salt using hashlib.scrypt.
    3. Use the private key with AES in GCM mode to encrypt the input message.
    4. Return the encrypted data (cipher text, salt, nonce, and tag) in a dictionary.
    def encrypt(plain_text, password):
        if not password:
            raise ValueError("Password cannot be empty.")
    
        salt = get_random_bytes(AES.block_size)
        private_key = hashlib.scrypt(
            password.encode(), salt=salt, n=2**14, r=8, p=1, dklen=32
        )
        cipher_config = AES.new(private_key, AES.MODE_GCM)
        cipher_text, tag = cipher_config.encrypt_and_digest(bytes(plain_text, "utf-8"))
        return {
            "cipher_text": b64encode(cipher_text).decode("utf-8"),
            "salt": b64encode(salt).decode("utf-8"),
            "nonce": b64encode(cipher_config.nonce).decode("utf-8"),
            "tag": b64encode(tag).decode("utf-8"),
        }
    

Step 3: Define Decryption Function

  • Create a function decrypt to:
    1. Recreate the private key from the password and salt.
    2. Decrypt the cipher text using AES in GCM mode and verify the integrity using the tag.
    3. Return the original message.
    def decrypt(enc_dict, password):
        if not password:
            raise ValueError("Password cannot be empty.")
    
        try:
            salt = b64decode(enc_dict["salt"])
            cipher_text = b64decode(enc_dict["cipher_text"])
            nonce = b64decode(enc_dict["nonce"])
            tag = b64decode(enc_dict["tag"])
            private_key = hashlib.scrypt(
                password.encode(), salt=salt, n=2**14, r=8, p=1, dklen=32
            )
            cipher = AES.new(private_key, AES.MODE_GCM, nonce=nonce)
            decrypted = cipher.decrypt_and_verify(cipher_text, tag)
            return decrypted.decode("utf-8")
        except (ValueError, KeyError) as e:
            raise ValueError("Invalid encrypted message format.") from e
    

Step 4: Add File Save Functionality

  • Create save_to_file to save encrypted data as a JSON file:
    def save_to_file(data):
        file_path = filedialog.asksaveasfilename(
            defaultextension=".json",
            filetypes=[("JSON Files", "*.json"), ("All Files", "*.*")],
        )
        if file_path:
            with open(file_path, "w") as file:
                json.dump(data, file)
            messagebox.showinfo("Success", f"Encrypted data saved to {file_path}")
    

Step 5: Add File Load Functionality

  • Create load_from_file to load encrypted data from a JSON file:
    def load_from_file():
        file_path = filedialog.askopenfilename(
            filetypes=[("JSON Files", "*.json"), ("All Files", "*.*")]
        )
        if file_path:
            with open(file_path, "r") as file:
                return json.load(file)
        else:
            raise FileNotFoundError("No file selected")
    

Step 6: Create GUI Handlers

1. Encryption Handler

  • Handle encryption and:
    • Display encrypted data.
    • Save it to a file if the user chooses.
    • Clear input fields after processing.
    def handle_encrypt():
        try:
            password = password_entry.get()
            plain_text = message_text.get("1.0", tk.END).strip()
            if not plain_text:
                raise ValueError("Message cannot be empty.")
    
            encrypted = encrypt(plain_text, password)
            result_text.delete("1.0", tk.END)
            result_text.insert(tk.END, json.dumps(encrypted, indent=4))
            if messagebox.askyesno("Save Encrypted Data", "Do you want to save the encrypted data to a file?"):
                save_to_file(encrypted)
    
            # Clear input fields
            password_entry.delete(0, tk.END)
            message_text.delete("1.0", tk.END)
    
        except Exception as e:
            messagebox.showerror("Error", str(e))
    

2. Decryption Handler

  • Handle decryption and:
    • Load encrypted data from a file.
    • Display the decrypted message.
    • Clear input fields after processing.
    def handle_decrypt():
        try:
            password = password_entry.get()
            encrypted = load_from_file()
            decrypted_message = decrypt(encrypted, password)
            result_text.delete("1.0", tk.END)
            result_text.insert(tk.END, decrypted_message)
    
            # Clear input fields
            password_entry.delete(0, tk.END)
    
        except Exception as e:
            messagebox.showerror("Error", str(e))
    

Step 7: Build the GUI

  1. Create the main window:

    root = tk.Tk()
    root.title("Secure Password Manager App")
  2. Add input fields for the password and message:

    tk.Label(root, text="Password:").grid(row=0, column=0, padx=10, pady=5)
    password_entry = tk.Entry(root, show="*", width=40)
    password_entry.grid(row=0, column=1, padx=10, pady=5)
    
    tk.Label(root, text="Message:").grid(row=1, column=0, padx=10, pady=5)
    message_text = tk.Text(root, height=10, width=50)
    message_text.grid(row=1, column=1, padx=10, pady=5)
    
  3. Add buttons for encryption and decryption:

    encrypt_button = tk.Button(root, text="Encrypt", command=handle_encrypt, width=15)
    encrypt_button.grid(row=2, column=0, padx=10, pady=10)
    
    decrypt_button = tk.Button(root, text="Decrypt", command=handle_decrypt, width=15)
    decrypt_button.grid(row=2, column=1, padx=10, pady=10)
    
  4. Add an output area to display results:

    tk.Label(root, text="Result:").grid(row=3, column=0, padx=10, pady=5)
    result_text = tk.Text(root, height=10, width=50)
    result_text.grid(row=3, column=1, padx=10, pady=5)
    
  5. Start the GUI application:

    root.mainloop()
    

Step 8: Run the Program

  • Save the complete code in a Python file (e.g., aes_gui.py).
  • Install required libraries (pip install pycryptodome).
  • Run the script:
    python3 aes_gui.py
    

Now the GUI-based program provides user-friendly encryption and decryption with field-clearing and file management functionalities!

Post Views: 746
Python Tags:1password, bitwarden, gmail password manager, google password manager, my passwords, my saved passwords on this device, norton password manager app, norton password manager extension, password manager, password manager app apk, password manager app download, password manager app free, password manager app free download, password manager chrome, password manager google, passwords and accounts, samsung password manager, view saved passwords

Post navigation

Previous Post: Ensuring Database Consistency with Python Transactions: A Comprehensive Guide
Next Post: Types of Agents in AI: Exploring the Foundations of Intelligent Systems

More Related Articles

Python Multiprocessing: A Complete Guide - Screenshot 2024-11-29 200152 Python Multiprocessing: A Complete Guide Python
Python assert Keyword: An Essential Debugging Tool - Python assert Keyword Python assert Keyword: An Essential Debugging Tool Python
Python OpenCV Object Detection: A Step-by-Step Guide - Python OpenCV Object Detection Python OpenCV Object Detection: A Step-by-Step Guide Python

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may also like

  1. Python Decorators: A Comprehensive Guide
  2. How to Calculate Distance between Two Points using GEOPY
  3. Rock, Paper, Scissors Game
  4. Fetcher App Using Python and Tkinter
  5. How to Install Django: Step-by-Step Guide
  6. Python Tkinter Canvas: A Guide to Structured Graphics in Python

Most Viewed Posts

  1. Top Large Language Models in 2025
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. login form in php and mysql , Step-by-Step with Free Source Code
  4. Flipkart Clone using PHP And MYSQL Free Source Code
  5. News Portal Project in PHP and MySql Free Source Code
  6. User Login & Registration System Using PHP and MySQL Free Code
  7. Top 10 Final Year Project Ideas in Python
  8. Online Bike Rental Management System Using PHP and MySQL
  9. E learning Website in php with Free source code
  10. E-Commerce Website Project in Java Servlets (JSP)
  • AI
  • ASP.NET
  • Blockchain
  • ChatCPT
  • code Snippets
  • Collage Projects
  • Data Science Project
  • Data Science Tutorial
  • DBMS Tutorial
  • Deep Learning Tutorial
  • Final Year Projects
  • Free Projects
  • How to
  • html
  • Interview Question
  • Java Notes
  • Java Project
  • Java Script Notes
  • JAVASCRIPT
  • Javascript Project
  • JSP JAVA(J2EE)
  • Machine Learning Project
  • Machine Learning Tutorial
  • MySQL Tutorial
  • Node.js Tutorial
  • PHP Project
  • Portfolio
  • Python
  • Python Interview Question
  • Python Projects
  • PythonFreeProject
  • React Free Project
  • React Projects
  • Spring boot
  • SQL Tutorial
  • TOP 10
  • Uncategorized
  • Online Examination System in PHP with Source Code
  • AI Chatbot for College and Hospital
  • Job Portal Web Application in PHP MySQL
  • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
  • Online Job Portal System in JSP Servlet MySQL

Most Viewed Posts

  • Top Large Language Models in 2025 (8,615)
  • Online Shopping System using PHP, MySQL with Free Source Code (5,218)
  • login form in php and mysql , Step-by-Step with Free Source Code (4,872)

Copyright © 2026 UpdateGadh.

Powered by PressBook Green WordPress theme