Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *Reddit's /r/dailyprogrammer easy challenge #5
- */
- #include <iostream>
- #include <fstream>
- using namespace std;
- void passwordProtect();
- int main()
- {
- passwordProtect();
- }
- void passwordProtect()
- {
- //strings to hold the user inputed user name and password
- string userName;
- string password;
- //string to hold the username and password from the text file
- string fileUserName;
- string filePassword;
- //setting up the inStream & outStream
- ifstream inStream;
- ofstream outStream;
- cout << "Enter in your username: " << endl;
- cin >> userName;
- cout << "Enter in your password: " << endl;
- cin >> password;
- //opens the text file with the username and password
- inStream.open("userName.txt");
- //gets the first line in the text file, which is the username, stores it in a string.
- getline(inStream, fileUserName);
- //gets the next line, which is the password and stores it to a string.
- getline(inStream, filePassword);
- //closes the file
- inStream.close();
- //simple if else, if every thing matches, you did it right else there is a error.
- if(userName == fileUserName && password == filePassword)
- {
- cout << "User name and password is correct, Welcome!" << endl;
- }
- else
- {
- cout << "ERROR" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement