C++ IF STATEMENT

I don't know if can actually do this in c++ but how take information save from data file or text file and try to set up user and password accout for user hear my code once he completes that weather he exit program or uses option 1 to login in how do a create it into if statement that he uses the correct password and user id and if you doesnt the write something like cout << accessed denied in currect password or user id hear is my code so far


#include <fstream>
#include <iostream>
#include <string>


using namespace std;


int UserSetup();
int Login();
int Quit();


int main()

{

int choice;

cout << "Welcome to the Tropical Island Game" << endl;
cout << "Login Enter 1" << endl;
cout << "Create New Account Enter 2" << endl;
cout << "Press 3 to Quit" << endl;
cin >> choice;

switch (choice) {

case 1:
Login();
break;
case 2:
UserSetup();
break;
case 3:
Quit();
break;

cin.get();

}
}


// The User password size and domain
std::string getStringOfMinLength(const std::string& prompt, unsigned minLength)
{
std::cout << prompt << '\n' << "(min length = " << minLength << ")\n" ;
std::string str ;
while ( std::cin >> str && str.length() < minLength )
std::cout << "Not long enough! (min length = " << minLength << ")\n" ;

return str;
}
// The User password size and domain

int UserSetup()

{
string password2;
ofstream Users("Users.txt",ios::app);
std::string userName = getStringOfMinLength("Please enter a user ID", 6) ;
repeat2:
std::string password1 = getStringOfMinLength("Please enter a password", 7) ;
cout << "Please RENTER your password\n";
cin >> password2;

if (password1 != password2)
{
cout << "You have ReEnter your password incorrectly \n";
goto repeat2;
}

if (password1 == password2)
{
cout << "You Now registered with Tropical Island\n";
cout << " User name: " << userName << " Password: " << password1 << '\n';
}

Users << userName << ' ' << password1 << endl;
Users.close();
main();

system ("pause");
}

int Login()
{
string UserID;
string password;

cout << "Please enter userID\n";
cin >> UserID;
cout << "Pleser enter password\n";
cin >> password;
}

int Quit()
{
return 0;
}






















Topic archived. No new replies allowed.