Skip to main content

Featured

Solving Economic Crisis Without Work-From-Home: A Systems Approach to Resource Prioritization

  1. The Economic Problem: Diagnosing the Crisis Type 1.1 Crisis Typology and Sector Dynamics Currency crises typically emerge from one or more of these imbalances: Current account deficits — Imports exceed exports; forex drains to cover the gap Capital account withdrawal — Foreign investors exit; hot money leaves Inflation-driven overvaluation — Real exchange rate strengthens despite nominal devaluation Debt servicing burden — External debt payouts drain reserves faster than exports can cover The empirical record shows that currency crises are sectoral crises —not aggregate demand crises. When Argentina devalued 75% in 2001, the economy contracted 10.9%, but manufacturing capacity utilization recovered within 18 months because input costs fell (Hausmann & Velasco, 2002). When Vietnam reformed in 1986, manufacturing capacity expansion drove recovery before demand-side effects materialized. Critical insight: Resource reallocation works when the constraint is supply-sid...

Python Project Password Manager With Encryption

1. Encryption and Decryption of Passwords:

   - Encryption: Passwords are encrypted before being stored using the `Fernet` encryption from the `cryptography` library. This ensures that the passwords are stored securely in the JSON file.

   - Decryption: When viewing passwords, the stored encrypted passwords are decrypted to reveal the original password.

 

 2. Password Management:

   - Add Password: Users can add passwords for different services. The service name, username, and encrypted password, along with a timestamp, are stored in a JSON file specific to that service.

   - View Passwords: Users can view all stored passwords for a particular service. The encrypted passwords are decrypted and displayed along with the associated username and timestamp.

 

 3. JSON-Based Storage:

   - Passwords are stored in JSON files, with each service having its own file (e.g., `google.json`, `instagram.json`). This makes it easy to categorize and manage passwords for different services.

 

 4. Menu-Driven Interface:

   - The program uses a simple text-based menu to allow the user to choose between adding a password, viewing stored passwords, or exiting the program.

 

 5. Timestamping:

   - Each password entry is timestamped with the exact date and time when it was added. This helps in keeping track of when each password was stored.

 

 6. Key Management:

   - The encryption key is loaded from a file (`secret.key`). This key is essential for both encrypting and decrypting passwords and must be securely stored.

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

# Generate a key for encryption (do this once and save the key securely)
# key = Fernet.generate_key()
# with open("secret.key", "wb") as key_file:
#     key_file.write(key)

# Load the encryption key from a file
def load_key():
    return open("secret.key", "rb").read()

# Encrypt a password
def encrypt_password(password, key):
    fernet = Fernet(key)
    return fernet.encrypt(password.encode()).decode()

# Decrypt a password
def decrypt_password(encrypted_password, key):
    fernet = Fernet(key)
    return fernet.decrypt(encrypted_password.encode()).decode()

def add_password(service, username, password, key):
    filename = f"{service}.json"
    timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')

    encrypted_password = encrypt_password(password, key)

    new_entry = {
        'username': username,
        'password': encrypted_password,
        'timestamp': timestamp
    }

    if os.path.exists(filename):
        with open(filename, 'r') as file:
            data = json.load(file)
    else:
        data = []

    data.append(new_entry)

    with open(filename, 'w') as file:
        json.dump(data, file, indent=4)

    print(f"Password for {service} added successfully!")

def view_passwords(service, key):
    filename = f"{service}.json"

    if os.path.exists(filename):
        with open(filename, 'r') as file:
            data = json.load(file)

        print(f"\nPasswords for {service}:")
        for entry in data:
            decrypted_password = decrypt_password(entry['password'], key)
            print(f"Username: {entry['username']}")
            print(f"Password: {decrypted_password}")
            print(f"Date Added: {entry['timestamp']}")
            print('-' * 30)
    else:
        print(f"No passwords stored for {service}.")

def main():
    key = load_key()

    while True:
        print("\nMenu:")
        print("1. Add Password")
        print("2. View Passwords")
        print("3. Exit")

        choice = input("Enter your choice: ")

        if choice == '1':
            service = input("Enter the service name (e.g., Instagram, Google): ").lower()
            username = input("Enter your username: ")
            password = input("Enter your password: ")
            add_password(service, username, password, key)
        elif choice == '2':
            service = input("Enter the service name (e.g., Instagram, Google): ").lower()
            view_passwords(service, key)
        elif choice == '3':
            print("Exiting the program.")
            break
        else:
            print("Invalid choice, please try again.")

if __name__ == "__main__":
    main

Comments

Popular Posts