Simple Password Manager Project in Python (Educational Console App)

← Back to Projects

Simple Password Manager in Python (Console-Based Project)

A password manager is a common real-world application that helps developers understand how data storage, file handling, and user input work together. In this project, you’ll build a simple console-based password manager using Python to learn how credentials can be stored, retrieved, and managed locally.

This project focuses on programming concepts and is intended for educational purposes only.

About the project: This is a Password Manager project in Python. This is a self-contained script that allows you to securely store and retrieve your passwords from your console.

This program will be a simple, console-based application that stores password entries (a service name and the corresponding password) in a local file. The data will be saved to a JSON file, so your entries are persistent.

    Important Security Note
  • This is a basic, educational project intended strictly for learning and demonstration purposes.
  • The passwords are saved in a simple, non-encrypted format in a local file. Do not use this application to store your real passwords or other sensitive information.
  • A real-world password manager would require robust encryption and a master password for security.
  • Do NOT use this application to store real or sensitive credentials.

Production-grade password managers use strong encryption algorithms,secure key storage, and master-password protection.


As noted above, this project is designed for learning and demonstration.

If you wanted to make a real, secure password manager, the next steps would be to add a master password and implement a strong encryption algorithm (like AES) to protect the data in the passwords.json file.


What You Will Learn From This Project

  • How to read and write JSON files in Python
  • How to build menu-driven console applications
  • How to safely accept password input using getpass
  • How to structure small Python projects
  • Basic principles behind password storage systems

How This Password Manager Works

  • The application stores password entries in a local JSON file.
  • Each entry consists of a service name and its corresponding password.
  • When the program runs, it loads existing data from the file, allows you to add or retrieve passwords, and saves changes before exiting.

Project Level: Intermediate

You can directly copy the below snippet code with the help of green copy button, paste it and run it in any Python editor you have.

Steps: Follow these steps

Step 1: Copy below code using green 'copy' button.

Step 2: Paste the code on your chosen editor.

Step 3: Save the code with filename and .py extention.

Step 4: Run (Press F5 if using python IDLE)




# password_manager.py

import json
import os
import getpass # A library to securely read passwords without echoing to the console.

# Filename for storing passwords
PASSWORDS_FILE = "passwords.json"

def load_passwords():
    """
    Loads password entries from a JSON file. Returns a dictionary of passwords.
    If the file doesn't exist, it returns an empty dictionary.
    """
    if os.path.exists(PASSWORDS_FILE) and os.stat(PASSWORDS_FILE).st_size > 0:
        try:
            with open(PASSWORDS_FILE, 'r') as f:
                return json.load(f)
        except json.JSONDecodeError:
            print("Warning: Passwords file is corrupted or empty. Starting with a new password book.")
            return {}
    return {}

def save_passwords(passwords):
    """
    Saves the passwords dictionary to a JSON file.
    """
    with open(PASSWORDS_FILE, 'w') as f:
        json.dump(passwords, f, indent=4)
    print("Passwords saved successfully.")

def add_password(passwords):
    """
    Prompts the user for a new password entry and adds it to the dictionary.
    """
    service = input("Enter the service name (e.g., Google, Twitter): ").strip()
    if not service:
        print("Service name cannot be empty. Password not added.")
        return
    
    # Use getpass to hide the password input in the console
    password = getpass.getpass("Enter the password: ").strip()

    if not password:
        print("Password cannot be empty. Password not added.")
        return

    passwords[service.lower()] = password
    print(f"Password for '{service}' added.")

def get_password(passwords):
    """
    Retrieves and displays a password for a given service name.
    """
    service = input("Enter the service name to retrieve the password for: ").strip()
    if not service:
        print("Service name cannot be empty.")
        return

    retrieved_password = passwords.get(service.lower())
    if retrieved_password:
        print(f"\nPassword for '{service}': {retrieved_password}")
    else:
        print(f"No password found for service '{service}'.")

def main():
    """
    Main function to run the Password Manager app with a menu.
    """
    passwords = load_passwords()

    print("--- Python Simple Password Manager ---")
    
    while True:
        print("\nMenu:")
        print("1. Add a new password")
        print("2. Get a password")
        print("3. Quit and Save")

        choice = input("Enter your choice (1-3): ").strip()

        if choice == '1':
            add_password(passwords)
        elif choice == '2':
            get_password(passwords)
        elif choice == '3':
            save_passwords(passwords)
            print("Exiting Password Manager. Goodbye!")
            break
        else:
            print("Invalid choice. Please enter a number between 1 and 3.")

# This ensures that main() is called only when the script is executed directly.
if __name__ == "__main__":
    main()




Ideas to Improve This Project

  • Add password strength validation
  • Encrypt the stored data using a library like cryptography
  • Add a master password for authentication
  • Create a GUI version using Tkinter
  • Store data in an encrypted database instead of a JSON file

Frequently Asked Questions


Is this password manager secure?

No. This project is intentionally simple and does not use encryption. It should only be used for learning purposes.

Can beginners build this project?

Yes. Basic knowledge of Python functions and file handling is sufficient.

Why use JSON for storage?

JSON is lightweight, easy to read, and ideal for small educational projects.



Related Python Projects



← Back to Projects