Fiveg_Tv

🔐 Project Overview

In this project, you will create a secure Password Manager that :

The current image has no alternative text. The file name is: IMG_20250820_023745_edit_143819127622325-scaled.jpg

✔ Saves usernames & passwords
✔ Encrypts all data
✔ Stores everything in a JSON file
✔ Allows you to add and retrieve credentials
✔ Uses a master password
✔ Real-world usefulness (similar to LastPass / 1Password basics)

You will learn:

  • Encryption using Fernet (cryptography module)
  • JSON handling
  • File operations
  • Secure input (getpass)
  • Functions, loops, dictionaries

⚙️ 1. Setup Requirements

Before running the project, install cryptography:

pip install cryptography

Create these two files:

1️⃣ password_manager.py
2️⃣ vault.json (empty JSON file)


🧾 2. Full Code: password_manager.py

import json
import os
from cryptography.fernet import Fernet
from getpass import getpass

# ----------- KEY MANAGEMENT -----------
def load_key():
    if os.path.exists("key.key"):
        with open("key.key", "rb") as key_file:
            return key_file.read()
    else:
        key = Fernet.generate_key()
        with open("key.key", "wb") as key_file:
            key_file.write(key)
        return key

key = load_key()
fernet = Fernet(key)


# ----------- LOAD & SAVE ENCRYPTED DATA -----------
def load_data():
    if os.path.exists("vault.json"):
        with open("vault.json", "rb") as file:
            encrypted = file.read()
            if encrypted:
                try:
                    decrypted = fernet.decrypt(encrypted)
                    return json.loads(decrypted)
                except:
                    return {}
            return {}
    return {}

def save_data(data):
    encrypted = fernet.encrypt(json.dumps(data).encode())
    with open("vault.json", "wb") as file:
        file.write(encrypted)


# ----------- PASSWORD MANAGER FUNCTIONS -----------
def add_password(vault):
    website = input("Website: ").strip()
    username = input("Username: ").strip()
    password = getpass("Password (hidden): ")

    vault[website] = {"username": username, "password": password}
    save_data(vault)
    print("✔ Password saved successfully!\n")


def view_password(vault):
    website = input("Enter website name: ").strip()

    if website in vault:
        print("\n🔐 Stored Credentials:")
        print(f"Website: {website}")
        print(f"Username: {vault[website]['username']}")
        print(f"Password: {vault[website]['password']}\n")
    else:
        print("❌ No credentials found for this website.\n")


def list_all(vault):
    if not vault:
        print("No passwords stored.\n")
        return

    print("\n📜 Saved Websites:")
    for site in vault.keys():
        print(f"- {site}")
    print()


# ----------- MASTER PASSWORD SYSTEM -----------
MASTER_PASSWORD = "admin123"   # <-- You can change this

def check_master():
    attempts = 3
    while attempts > 0:
        pwd = getpass("Enter Master Password: ")
        if pwd == MASTER_PASSWORD:
            print("✔ Access granted!\n")
            return True
        attempts -= 1
        print("❌ Wrong password. Attempts left:", attempts)
    print("🚫 Access denied.")
    exit()


# ----------- MAIN MENU -----------
def main():
    check_master()
    vault = load_data()

    while True:
        print("🔐 Password Manager")
        print("1. Add Password")
        print("2. View Password")
        print("3. List All Websites")
        print("4. Exit")

        choice = input("👉 Choose (1-4): ")

        if choice == "1":
            add_password(vault)
        elif choice == "2":
            view_password(vault)
        elif choice == "3":
            list_all(vault)
        elif choice == "4":
            print("Goodbye!")
            break
        else:
            print("❌ Invalid choice.\n")


if __name__ == "__main__":
    main()

🖥 3. How to Run

  1. Save the code in:
password_manager.py
  1. Create an empty file:
vault.json
  1. Open CMD inside the folder and run:
python password_manager.py

📌 4. Example Usage

🔑 Master Password

Enter Master Password:
✔ Access granted!

➕ Add a password

Website: github.com
Username: john
Password: ****
✔ Password saved successfully!

🔎 View a password

Enter website name: github.com
Website: github.com
Username: john
Password: mySecret123

📜 List all saved websites

- github.com
- gmail.com

🧠 5. Summary Table
FeatureDescription
EncryptionAll data encrypted using Fernet
Master PasswordProtects access
Add PasswordStores website, username, password
View PasswordDecrypts and displays data
JSON StoragePersistent encrypted storage
Hidden InputSecure password entry

🎉 Project Completed!

This Password Manager is a strong foundation for future upgrades.

⬇️ Download FiveG_Pro تحميل Server

Related Posts

Djoker_tv

🧾 Project Overview In this project, you will build a Python Expense Tracker App that allows users to: ✔ Add new expenses✔ View all expenses✔ Search by category✔ Calculate total…

Read more

FlyFeditv

📘 Introduction In this project, you’ll create a command-line Expense Tracker that allows users to: ✅ Add expenses with category, amount, and description✅ View total spending and category breakdown✅ Automatically…

Read more

NetCinFly

📘 Introduction In this project, you’ll develop a Student Grades Analyzer in Python that can: This project helps you strengthen your skills with lists, dictionaries, loops, and data analysis logic….

Read more

Eagle_Pro

🌐 Introduction In this project, you’ll create a Web Scraper App in Python that extracts quotes, authors, and tags from a live website.You’ll use the BeautifulSoup and Requests libraries to…

Read more

Cobra_Pro

🌦️ Introduction In this project, you’ll build a Weather App in Python that retrieves live weather information from an online API.You’ll learn how to work with HTTP requests, JSON data,…

Read more

Show7-Pro

Concepts Covered: 🎯 Objective: Create a simple, text-based contact book application that allows users to: 💡 Code (contact_book.py): 🧠 Example Usage Console Output Example: 💾 Notes ⬇️ Download Show7-Pro تحميل…

Read more