class Password /* Password class... will store all necessary data */
{
protected: /* A password should be protected, right? */
string password; /* The string to store the password */
string input; /* The string to store the input */
public:
/* Constructor, pass a string to it (the actual password) */
Password (string pass) {this->password = pass;}
void Input () /* Get the password from the user */
{
while (true) /* Infinite loop, exited when RETURN is pressed */
{
char temp;
temp= getch (); /* Get the current character of the password */
if (GetAsyncKeyState (VK_RETURN)) /* If the user has pressed return */
return; /* Exit the function */
input += temp;
cout << '*'; /* Print a star */
}
}
bool Compare () /* Check if the input is the same as the password */
{
if (password.length() != input.length()) /* If they aren't the same length */
return false; /* Then they obviously aren't the same! */
for (unsigned int i = 0; i <= input.length(); i++)
{ /* Loop through the strings */
if (password[i] != input[i])
return false; /* If anything is not a match, then they are not the same */
}
return true; /* If all checks were passed, then they are the same */
}
};
string pwpw()
{
Password pass ("ilove03"); /* Assign password a value with our constructor */
cout<<" PASSWORD: ";
pass.Input (); /* Get the input from the user */
if (pass.Compare()) /* If they match, user could gain access to something */
cout << "\nThat's correct!";
else /* Otherwise, give them some abuse! */
wrongpw();
cin.get (); /* Pause for input */
return EXIT_SUCCESS; /* Program was executed successfully */