Example #1
0
int main(int argc, char *argv[])
{
	int r = 0;
	Console console;
	std::string input;
	bool userIsLoggedIn = false;
	
	console.init();
	
	while (1)
	{
		input = console.read();
		std::transform(input.begin(), input.end(), input.begin(), ::toupper);
		// split the string of input
		std::stringstream strstream(input); // strstream is used for splitting 
											// the input
		std::istream_iterator<std::string> start(strstream);
		std::istream_iterator<std::string> end;
		std::vector<std::string> input_split(start, end);
		strstream.clear();

		if (input_split.size() < 1)
			break;
		
		if (input_split[0] == "LOGON")
		{
			bool founduser = false, foundpass = false;
			std::string username;
			// user wants to log on
			console.delay(750);
			
			if (input_split.size() < 2)
			{
				console.write("\nENTER USERNAME NOW\n\n");
				username = console.read();
				console.delay(750);
			}
			else
			    username = input_split[1];
			
			for (int i = 0; i<arraysize(usernames); i++)
			{
				if (username == usernames[i])
				{
					founduser = true;
					console.write("\nENTER PASSWORD NOW\n\n");
					std::string password = console.read();
					if (password == userpasswords[i])
					{
						userIsLoggedIn = true;
						foundpass = true;
						console.write("\nWELCOME, ");
						console.write(username);
						console.write(".\n\n");
						r = consoleSession(console, i);
					}
					else
						console.write("\nERROR - INCORRECT PASSWORD\n\n");
				}
			}
			
			if (!founduser)
				console.write("\nERROR - USER DOES NOT EXIST\n\n");
			else
			{
				if (userIsLoggedIn)
				{
					if (r == 0)
					    break;
					else
					    userIsLoggedIn = false;
				}
			}
		}
		else if (input_split[0] == "EXIT")
			break;
		else
			console.write("\nERROR - USER MUST BE LOGGED ON\n");

		console.writeNoDelay("\n");
	}

	return 0;
}