Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <windows.h>
- #include <string>
- #include <fstream>
- #include "login.h"
- using namespace std;
- login::login() // Constructor
- {
- accountusername = "";
- accountpassword = "";
- }
- void login::homeScreen()
- {
- system("CLS");
- cout << "__________________[HOME]____________________" << endl;
- cout << "-Enter 'Login' to begin login" << endl;
- cout << "-Enter 'Register' to register an account" << endl;
- cout << "-Enter 'ForgotInfo' to recover account info\n" << endl;
- cout << "[";
- string homechoice;
- cin >> homechoice;
- if(homechoice == "Login" || homechoice == "login")
- loginScreenU();
- else if(homechoice == "Register" || homechoice == "register")
- registerScreenU();
- else if(homechoice == "ForgotInfo" || homechoice == "forgotinfo")
- forgotinfoScreen();
- else
- {
- cout << "- ERROR: Invalid Entry -- Please enter a valid choice." << endl;
- Sleep(1500);
- homeScreen();
- }
- }
- void login::loginScreenU()
- {
- system("CLS");
- cout << "Username: ";
- string username;
- cin >> username;
- verifyUsername(username);
- if(verifyUsername(username) == true)
- loginScreenP();
- while(verifyUsername(username) == false)
- {
- system("CLS");
- cout << "ERROR: '" << username << "' is an invalid username - Please enter a valid username.\n" << endl;
- cout << "-If you would like to return to the main menu, please enter 'Menu'." << endl;
- cout << "Username: ";
- cin >> username;
- if(username == "Menu" || username == "menu")
- homeScreen();
- }
- }
- void login::loginScreenP()
- {
- system("CLS");
- cout << "Password: ";
- string password;
- cin >> password;
- verifyPassword(password);
- if(verifyPassword(password) == true)
- {
- system("CLS");
- cout << "Thank you for logging in!" << endl;
- }
- else
- {
- Sleep(1000);
- system("CLS");
- loginScreenP();
- }
- }
- void login::registerScreenU()
- {
- system("CLS");
- cout << "Thank you for choosing to register. Please fill out the info on screen." << endl;
- registerUsername();
- }
- void login::forgotinfoScreen()
- {
- system("CLS");
- if(accountusername == "")
- {
- cout << "You have not yet registered an account!" << endl;
- cout << "Returning to Main Menu..." << endl;
- Sleep(1500);
- system("CLS");
- homeScreen();
- }
- else
- {
- cout << "Security Question: " << securityquestion << endl;
- cin >> recoveryanswer;
- if(recoveryanswer == securityanswer)
- {
- cout << "\nUsername: " << accountusername << endl;
- cout << "Password: " << accountpassword << endl;
- cout << "\nReturning to Main Menu..." << endl;
- Sleep(2000);
- homeScreen();
- }
- else
- {
- cout << "ERROR: Invalid security question answer!" << endl;
- cout << "Returning to Main Menu..." << endl;
- Sleep(2000);
- homeScreen();
- }
- }
- }
- void login::registerUsername()
- {
- cout << "\nUsername: ";
- cin >> accountusername;
- if(accountusername.length()<4)
- {
- system("CLS");
- cout << "ERROR: Username must be greater than 4 characters!" << endl;
- registerUsername();
- }
- else if(accountusername.length()>10)
- {
- system("CLS");
- cout << "ERROR: Username must be less than 10 characters!" << endl;
- registerUsername();
- }
- else
- {
- system("CLS");
- registerPassword();
- }
- }
- void login::registerPassword()
- {
- cout << "Username: " << accountusername << endl;
- cout << "Password: ";
- cin >> accountpassword;
- ofstream outputFile("AccountInfo.txt");
- outputFile << accountusername << "\n"
- << accountpassword << endl;
- if(accountpassword.length()<4)
- {
- system("CLS");
- cout << "\nERROR: Password must be greater than 4 characters!" << endl;
- registerPassword();
- }
- else if(accountpassword.length()>10)
- {
- system("CLS");
- cout << "\nERROR: Password must be less than 10 characters!" << endl;
- registerPassword();
- }
- else
- {
- system("CLS");
- cout << "Username: " << accountusername << endl;
- cout << "Password: ";
- for(int i = 0; i < accountpassword.length(); i++)
- cout << "*";
- cout << "\nConfirm Password: ";
- cin >> confirmpassword;
- if(confirmpassword == accountpassword)
- {
- system("CLS");
- cout << "One last step, please select the number for a security question you would like:" << endl;
- securityQuestion();
- }
- else
- {
- cout << "\nERROR: Passwords do not match!" << endl;
- Sleep(1000);
- system("CLS");
- registerPassword();
- }
- }
- }
- void login::securityQuestion()
- {
- cout << "1. What is the name of your first pet?" << endl;
- cout << "2. What is your Mother's middle name?" << endl;
- cout << "3. What is your Father's middle name?" << endl;
- cout << "- ";
- int choice;
- cin >> choice;
- if(choice == 1)
- {
- system("CLS");
- cout << "1. What is the name of your first pet?" << endl;
- securityquestion = "What is the name of your first pet?";
- cin >> securityanswer;
- system("CLS");
- accountCreated();
- }
- else if(choice == 2)
- {
- system("CLS");
- cout << "2. What is your Mother's middle name?" << endl;
- securityquestion = "What is your Mother's middle name?";
- cin >> securityanswer;
- system("CLS");
- accountCreated();
- }
- else if(choice == 3)
- {
- system("CLS");
- cout << "3. What is your Father's middle name?" << endl;
- securityquestion = "What is your Father's middle name?";
- cin >> securityanswer;
- system("CLS");
- accountCreated();
- }
- else
- {
- system("CLS");
- securityQuestion();
- }
- }
- void login::accountCreated()
- {
- cout << "Thank you for registering!" << endl;
- cout << "Returning to Main Menu..." << endl;
- Sleep(2000);
- system("CLS");
- homeScreen();
- }
- bool login::verifyUsername(string user)
- {
- ifstream inputFile("AccountInfo.txt");
- inputFile.open("AccountInfo.txt");
- string first_line;
- if(inputFile.is_open())
- {
- if(inputFile.good())
- getline(inputFile, first_line);
- inputFile.close();
- }
- else
- {
- cout << "ERROR: Cannot find Account Information!" << endl;
- cout << "Returning to Main Menu..." << endl;
- Sleep(2000);
- system("CLS");
- homeScreen();
- }
- if(user == first_line)
- return true;
- else
- return false;
- }
- bool login::verifyPassword(string pass)
- {
- if(pass == accountpassword)
- return true;
- else
- {
- cout << "ERROR: Invalid Password!" << endl;
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment