Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- string username;
- string password;
- int choice;
- string eUsername;
- string ePassword;
- bool approved=false;
- void startUp () {
- cout << "To begin create an account, or log in!" << endl;
- cout << " To log in Enter '1' \n To create an account enter '2'" << endl;
- cin >> choice;
- }
- void loggingIn () {
- cout << "Enter your username" << endl;
- cin >> eUsername;
- cout << "Enter your password" << endl;
- cin >> ePassword;
- ifstream inProfileData ("logIn.txt");
- inProfileData >> username >> password;
- if (password==ePassword&&username==eUsername) {
- approved=true;
- }
- else {
- approved = false;
- }
- }
- void createAccount () {
- cout << "Create your username!" << endl;
- cin >> username;
- cout << "Good, now create a password" << endl;
- cin >> password;
- cout << "Good, now log in" << endl;
- ofstream profileData ("logIn.txt");
- profileData << username << " " << password << endl;
- }
- void logInBody () {
- startUp ();
- if (choice!=2&&choice!=1) {
- cout << "You must enter 1 or 2!" << endl << endl;
- startUp();
- }
- if (choice ==2) {
- createAccount ();
- loggingIn ();
- }
- if (choice == 1) {
- loggingIn();
- }
- if (approved==true) {
- cout << "Congratiolations, you are now logged in! Enjoy!" << endl;
- }
- else {
- cout << " Username or password was incorrect, or you entered wrong data type." << endl << endl;
- }
- }
- int main ()
- {
- int x=0;
- do {
- logInBody ();
- x++;
- }
- while (approved==false&&x<11);
- if (x==11) {
- cout << "Either you entered the wrong data type or you have reached the maximum amount of attempts allowed" << endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment