Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Program: Challenge 5
- Author: Chapman Siu
- Date: 5 Aug
- Description:
- Your challenge for today is to create a program which is password protected, and wont open unless the correct user and password is given.
- For extra credit, have the user and password in a seperate .txt file.
- for even more extra credit, break into your own program :)
- */
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- bool checkLogin(string User, string Pass);
- bool checkLogin(string User, string Pass) {
- ifstream loginDet;
- loginDet.open("login.txt");
- string loginUser, loginPass;
- if (loginDet.is_open()) {
- while(!loginDet.eof()) {
- getline(loginDet,loginUser);
- getline(loginDet,loginPass);
- }
- }
- loginDet.close();
- if (User == loginUser && Pass == loginPass) {
- return true;
- }
- cout <<endl << "Incorrect Details. Try Again" << endl;
- return false;
- }
- int main()
- {
- string user,pass;
- cout << "Enter Username: " <<endl;
- cin >> user;
- cout << "Enter Password: " << endl;
- cin >> pass;
- while(!checkLogin(user,pass)){
- cout << "Enter Username: " <<endl;
- cin >> user;
- cout << "Enter Password: " << endl;
- cin >> pass;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment