The Muggy Weather Robotics Duo

Image
 The Muggy Weather Robotics Duo A C++ System That Thinks, Feels (Sensors!), and Acts Humidity is like the quiet character in the weather story that actually runs the show. On muggy days, everything feels heavier—breathing, drying laundry, running machines, even keeping a data center cool. For people, it’s about comfort and health; for machines, it’s about performance and reliability; for plants and buildings, it’s about moisture balance and mold risk. In robotics and automation, muggy weather isn’t just a nuisance—it’s a signal . It tells your systems when to ventilate, when to dehumidify, when to throttle physically demanding tasks, and when to take preventative maintenance actions. Today, we’ll build a two-program C++ system that “understands” muggy weather: Program A — sensor_hub.cpp A sensor-side program that generates (or ingests) a live stream of environmental data (temperature, relative humidity, pressure, CO₂, VOCs). Think of it as your robotic nose and skin , con...

C++ Projects: Password Manager

C++ Projects: Password Manager

Welcome to the series of C++ projects. Here, I will guide you on how to build useful applications and systems using your C++ skills. These projects won't be extremely easy or beginner-friendly, but I will do my best to explain them in the clearest way possible. Let's build something great!

This project securely manages passwords by storing and retrieving them for different accounts. Passwords are encrypted before being saved to a file, and a master password is required for access.


Skills Used

  • File Handling: Reading and writing passwords to a file.
  • Encryption and Decryption: Using the Caesar cipher to secure passwords.
  • Conditional Statements: Handling account searches and invalid passwords.
  • String Manipulation: Encrypting and decrypting stored passwords.

Code to Build the Password Manager

#include <iostream>
#include <fstream>
#include <string>
#include <map>
using namespace std;

// Simple encryption function
string encryptPassword(const string &password) {
    string encrypted = password;
    for (char &c : encrypted) {
        c += 3; // Shift each character forward by 3
    }
    return encrypted;
}

// Simple decryption function
string decryptPassword(const string &password) {
    string decrypted = password;
    for (char &c : decrypted) {
        c -= 3; // Shift each character back by 3
    }
    return decrypted;
}

// Function to load passwords from file
void loadPasswords(map<string, string> &passwordMap) {
    ifstream file("passwords.txt");
    if (file.is_open()) {
        string account, encryptedPassword;
        while (file >> account >> encryptedPassword) {
            passwordMap[account] = encryptedPassword;
        }
        file.close();
    }
}

// Function to save passwords to file
void savePasswords(const map<string, string> &passwordMap) {
    ofstream file("passwords.txt");
    if (file.is_open()) {
        for (const auto &entry : passwordMap) {
            file << entry.first << " " << entry.second << "\n";
        }
        file.close();
    }
}

// Function to add a new password
void addPassword(map<string, string> &passwordMap) {
    string account, password;
    cout << "Enter the account name: ";
    cin >> account;
    cout << "Enter the password: ";
    cin >> password;

    string encryptedPassword = encryptPassword(password);
    passwordMap[account] = encryptedPassword;

    savePasswords(passwordMap);
    cout << "Password saved successfully!\n";
}

// Function to retrieve a password
void retrievePassword(const map<string, string> &passwordMap) {
    string account;
    cout << "Enter the account name: ";
    cin >> account;

    auto it = passwordMap.find(account);
    if (it != passwordMap.end()) {
        string decryptedPassword = decryptPassword(it->second);
        cout << "Password for " << account << ": " << decryptedPassword << "\n";
    } else {
        cout << "Account not found.\n";
    }
}

// Main menu function
void menu() {
    map<string, string> passwordMap;
    loadPasswords(passwordMap);

    string masterPassword = "admin123";
    string enteredPassword;

    cout << "----- Password Manager -----\n";
    cout << "Enter the master password to access: ";
    cin >> enteredPassword;

    if (enteredPassword != masterPassword) {
        cout << "Incorrect master password. Access denied.\n";
        return;
    }

    int choice;
    do {
        cout << "\n---- Menu ----\n";
        cout << "1. Add Password\n";
        cout << "2. Retrieve Password\n";
        cout << "3. Exit\n";
        cout << "Enter your choice: ";
        cin >> choice;

        switch (choice) {
            case 1:
                addPassword(passwordMap);
                break;
            case 2:
                retrievePassword(passwordMap);
                break;
            case 3:
                cout << "Exiting the Password Manager. Goodbye!\n";
                break;
            default:
                cout << "Invalid choice. Please try again.\n";
        }
    } while (choice != 3);
}

int main() {
    menu();
    return 0;
}

Real-World Examples and Applications

Personal Uses:

  • Securely store passwords for various virtual accounts.

Small Business:

  • Manage employee passwords for internal use.
  • IT support can securely store customer credentials.

Case Study: How Companies Secure Passwords

Example:

  • Popular services like Dashlane and LastPass use AES-256 encryption to protect user credentials.
  • This project uses a basic Caesar cipher for educational purposes, while real-world applications use stronger encryption such as salting and hashing.

Lessons Learned:

  • Always encrypt sensitive data before storing it.
  • Use multi-factor authentication (MFA) for added security.
  • Avoid storing passwords in plain text files.

Problem-Solving Approaches

Challenge: Weak Encryption

Solution: Replace Caesar cipher with a stronger hashing algorithm such as SHA-256.

Challenge: Vulnerable Files

Solution: Encrypt stored files or use a secure database with strict access control.

Challenge: Forgetting the Master Password

Solution: Implement a password recovery mechanism, such as email-based recovery or security questions.


Final Thoughts

This project is a great way to practice file handling, encryption, and conditional logic in C++. Although the encryption method used here (Caesar cipher) is simple and not suitable for real-world applications, it helps demonstrate the basics of securing passwords. For production-level security, consider using more advanced encryption techniques like AES (Advanced Encryption Standard) or hashing with salt (e.g., SHA-256 + PBKDF2).

I hope you enjoyed reading this blog and gained valuable insights! Stay tuned for more exciting C++ projects in the future!

Comments

Popular posts from this blog

C++ Projects: Basic Traffic Management System

C++ Projects: Book Shop Management System

🌿 Smart Garden Manager in C++ with Robotics, UI, Drones, and Sound "A Rainwater Conservation System for Tomorrow’s Farms"