Guest User

LOGIN SYSTEM

a guest
Jul 2nd, 2011
1,477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. // Advanced Login System by Sam Wharfe
  2. // Date started: 30/6/2011
  3. // To Be Done:
  4. // Able to read the attempted login info and confirm it by searching the user files.
  5. #include <iostream>
  6. #include <fstream>
  7. #include <string>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.     // Open userDB.dat for input
  14.     ifstream inUserDB("C:/userDB.dat");
  15.     // Open userDB.dat for output, and app (append) will add new text without removing the old
  16.     ofstream outUserDB("C:/userDB.dat", ios_base::app);
  17.     string checkUser;
  18.     string userIn;
  19.     string passIn;
  20.     string newUser;
  21.     string newPass;
  22.  
  23.     cout << "Username: ";
  24.     cin >> userIn;
  25.     cout << "Password: ";
  26.     cin >> passIn;
  27.     inUserDB >> checkUser; // converts the text in userDB.dat to the string
  28.  
  29.     while (userIn == checkUser || passIn == checkUser) // if what the user inputted does not match the database
  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.         ofstream createdUser(newUser); // Creates a file for the new users info. File name is the new username.
  38.  
  39.         createdUser << "Username: " << newUser << "\nPassword: " << newPass; // Adds the new user/pass to the database
  40.     }                                                                                                              
  41.  
  42.     system("PAUSE");
  43. }
Advertisement
Add Comment
Please, Sign In to add comment