Advertisement
Guest User

easy challenge 5

a guest
Feb 13th, 2012
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. /*
  2. *Reddit's /r/dailyprogrammer easy challenge #5
  3. */
  4.  
  5. #include <iostream>
  6. #include <fstream>
  7.  
  8.    using namespace std;
  9. void passwordProtect();
  10.    int main()
  11.    {
  12.         passwordProtect();
  13.    }
  14.    void passwordProtect()
  15.     {
  16.         //strings to hold the user inputed user name and password
  17.       string userName;
  18.       string password;
  19.       //string to hold the username and password from the text file
  20.       string fileUserName;
  21.       string filePassword;
  22.      
  23.     //setting up the inStream & outStream
  24.       ifstream inStream;
  25.       ofstream outStream;
  26.    
  27.       cout << "Enter in your username: " << endl;
  28.       cin >> userName;
  29.    
  30.       cout << "Enter in your password: " << endl;
  31.       cin >> password;
  32.     //opens the text file with the username and password
  33.       inStream.open("userName.txt");
  34.       //gets the first line in the text file, which is the username, stores it in a string.
  35.       getline(inStream, fileUserName);
  36.       //gets the next line, which is the password and stores it to a string.
  37.       getline(inStream, filePassword);
  38.       //closes the file
  39.       inStream.close();
  40.    
  41.     //simple if else, if every thing matches, you did it right else there is a error.
  42.       if(userName == fileUserName && password == filePassword)
  43.       {
  44.       cout << "User name and password is correct, Welcome!" << endl;
  45.       }
  46.       else
  47.       {
  48.          cout << "ERROR" << endl;
  49.       }
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement