Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     // Open userDB.dat for input
  10.     ifstream inUserDB("C:/userDB.dat");
  11.     // Open userDB.dat for output, and app (append) will add new text without removing the old
  12.     ofstream outUserDB("C:/userDB.dat", ios_base::app);
  13.     string checkUser;
  14.     string userIn;
  15.     string passIn;
  16.     string newUser;
  17.     string newPass;
  18.  
  19.     cout << "Username: ";
  20.     cin >> userIn;
  21.     cout << "Password: ";
  22.     cin >> passIn;
  23.     inUserDB >> checkUser; // converts the text in userDB.dat to the string
  24.  
  25.     if (userIn != checkUser || passIn != checkUser) // if what the user inputted does not match the database
  26.     {
  27.         cout << "LOGIN FAILED.";
  28.     }
  29.     else
  30.     {
  31.         cout << "Welcome " << userIn;
  32.         cout << "\nPlease enter the username you would like to add to the database: ";
  33.         cin >> newUser;
  34.         cout << "Please enter a password to be added to the new username: ";
  35.         cin >> newPass;
  36.  
  37.         outUserDB << "\n\n" << newUser << "\n" << newPass; // Adds the new user/pass to the database
  38.  
  39.         system("PAUSE");
  40.     }
  41.  
  42.     system("PAUSE");
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement