#include <iostream>
#include <vector>
#include <string>
using namespace std;
class PasswordEntry {
public:
string service;
string username;
string password;
PasswordEntry(string svc, string user, string pass)
: service(svc), username(user), password(pass) {}
};
class PasswordKeychain {
private:
vector<PasswordEntry> entries;
public:
void addEntry(const string& service, const string& username, const
string& password) {
entries.emplace_back(service, username, password);
cout << "Entry added successfully!" << endl;
}
void viewEntries() {
if (entries.empty()) {
cout << "No entries to display." << endl;
return;
}
cout << "\nPassword Keychain Entries:" << endl;
for (const auto& entry : entries) {
cout << "Service: " << entry.service
<< ", Username: " << entry.username
<< ", Password: " << entry.password << endl;
}
}
void searchEntry(const string& service) {
for (const auto& entry : entries) {
if (entry.service == service) {
cout << "Service: " << entry.service
<< ", Username: " << entry.username
<< ", Password: " << entry.password << endl;
return;
}
}
cout << "No entry found for the service: " << service << endl;
}
};
int main() {
PasswordKeychain keychain;
int choice;
do {
cout << "\nPassword Keychain Menu:" << endl;
cout << "1. Add Entry" << endl;
cout << "2. View Entries" << endl;
cout << "3. Search Entry" << endl;
cout << "4. Exit" << endl;
cout << "Choose an option: ";
cin >> choice;
switch (choice) {
case 1: {
string service, username, password;
cout << "Enter service name: ";