/***************************/
/** SECURE PASSWORD ENTRY **/
/** BY DANNY BATTISON **/
/** gabehabe@hotmail.com **/
/***************************/
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
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 */
}
};
int main ()
{
/*
* NOTE: We could get a password from anywhere here, for example,
* we could import it from an encrypted file
*/
cout<<"Please enter the password: \n"; //Added by Liam dickson
Password pass ("torchwood"); /* Assign password a value with our constructor */
pass.Input (); /* Get the input from the user */
if (pass.Compare()) /* If they match, user could gain access to something */
{
cout << "\n[PASSWORD ACCEPTED]\n";
cout << "This is the Torchwood system access with remote access\n";
}
else /* Otherwise, give them some abuse! */
{
cout << "\n[PASSWORD WRONG!]\n";
cout << "The system is shutting down!\n";
int x=0;
string message = "System shutting down!";
while ( message[x] != '\0')
{
cout << message[x];
Sleep(50);
x++;
};
cout<<"\n[Shutdown complete]";
return 0;
}
cin.get (); /* Pause for input */
return EXIT_SUCCESS; /* Program was executed successfully */
}