/** * Password Pro v1.0 by Adam Rawji * This application is used to store website usernames and passwords. * It is a C++ console application. */ #include #include #include using namespace std; int main() { // Introduce the application. cout << "Password Pro by Adam Rawji" << endl; cout << "Version 1.0" << endl << endl; ifstream myInputFStream; ofstream myOutputFStream; string input; string line; // Ask user for username and password. If no main account has been made before, the user will be prompted to // make an account. Main account information will be stored in the program directory as "mainaccount.pwp". The // user must enter the main account information correctly to continue. string username; string password; myInputFStream.open("mainaccount.pwp"); // open file with main account information if(myInputFStream.is_open()) { getline(myInputFStream, username); getline(myInputFStream, password); myInputFStream.close(); } else { cout << "Password Pro has encountered an error. The program will now shut down." << endl; //return 0; } cout << "What is your username?" << endl; cin >> input; while (input != username) { cout << "That is incorrect. Please try again." << endl; cin >> input; } cout << "What is your password?" << endl; cin >> input; while (input != password) { cout << "This is incorrect. Please try again." << endl; cin >> input; } // User has entered main information correctly. Initialize variables and file streams and then display the // main menu. int userchoice = 0; while (userchoice != 5) { cout << endl << endl << "Please select one of the following:" << endl; cout << "1. Add an entry." << endl; cout << "2. Find an entry." << endl; cout << "3. Change username." << endl; cout << "4. Change password." << endl; cout << "5. Exit program." << endl; cin >> userchoice; // Need to error check to make sure user types in an int value. // If user decides to add an entry, an entry will be added to the file "mainaccount.pwp" in the main // directory. if (userchoice == 1) { myOutputFStream.open("mainaccount.pwp", ios::app); // open file "mainaccount.pwp" to add entry at end of file cout << endl << "What is the name of the site?" << endl; cin >> input; myOutputFStream << endl << "name: " + input << endl; cout << "What is your username?" << endl; cin >> input; myOutputFStream << input << endl; cout << "What is your password?" << endl; cin >> input; myOutputFStream << input << endl; cout << endl << "Entry added." << endl; myOutputFStream.close(); } // If user decides to find an entry, the user will input the name of the site, which will be found in // the file "mainaccount.pwp". If name of site is found, the following two lines in the file will // correspond to the username and password for that site, which will be outputted to the user. if (userchoice == 2) { myInputFStream.open("mainaccount.pwp"); // open file "mainaccount.pwp" to find entry cout << endl << "What is the name of the site?" << endl; cin >> input; if (myInputFStream.is_open()) { // Go through every line in the file until the site is found. If site is found, display username // and password to the user (username is 1 line after site name in file and password is 2 lines // after site name in file). bool sitefound = false; while (myInputFStream.good()) { getline(myInputFStream, line); if (line == "name: " + input) { sitefound = true; getline(myInputFStream, line); cout << "Username: " << line << endl; getline(myInputFStream, line); cout << "Password: " << line << endl; } } if (sitefound == false) { cout << "Site was not found." << endl; } myInputFStream.close(); } else { cout << "Password Pro has encountered an error. The program will now shut down." << endl; return 0; } } // If user decides to change username, change the username in the file "mainaccount.pwp". if (userchoice == 3) { cout << "Coming soon." << endl; } if (userchoice == 4) { cout << "Coming soon." << endl; } } return 0; }