ugh, anyway, got a chance to revise this program. now I need beta testers for this proggy. this is what I have so far. I will be continuing on this later on.
Code:
// LOCK(MultipleCodeLock via code4,length8,time10) security application
// _lock.exe, _lock.cpp
// version gds2002042015beta
// written by K.L. , a.k.a. "toaster", http://www.cprogramming.com
// using MSDEV VSC++ 6.0 (Win32 Console Application)
//#include<stdlib.h> // for system()
#include<stdio.h> // for printf()
#include<conio.h> // for getch()
//#incldue<time.h> // for timediff() (is spelling/syntax correct?)
short unsigned int i; //to save some memory
//bool toggle; //variable is now a local in main; made into local
//void option()
//{
//printf("-configuration\n"); //change password, etc...
//printf("-continue\n"); //leave program and continue (to O.S.)
//}
// fills in the rest of the spaces with asterisks after code is entered
// to prevent others from seeing length of code
void fillcode(int i)
{
for(i;i<8;i++)
{
printf("*");
}
printf("]\n");
}
// user has to input code
// don't know if there are any loopholes in this yet
// so far prevented [Ctrl+C] and [Alt+F4], hopefully
void inputcode(char*&input)
{
for(i=0;i<8;i++)
{
input[i]=getch();
printf("*");
fflush(stdout);
if(input[i]==char(13)){break;}
if(input[i]==' '){break;} //look up: ASCII value of ' '
}
fillcode(++i);
}
bool /*void*/ comparecode(const char*input,const char*code,bool&toggle)
//why can't input and code be set to reference? what did I do wrong?
//merged comparecode and tofalse together
{
for(i=0;i<8;i++)
{
if( ( ( input[i]==char(13) ) || (input[i]==' ') ) && ( code[i]==char(0) ) )
{
toggle=true;
return true;
}
if( input[i]!=code[i] )
{
toggle=false;
return false;
}
}
toggle=false; //fail safe
return false; //fail safe (error trap)
}
//void tofalse(bool &toggle) //info on reference parameter on comments below
//can make either reference (for local type) or no reference (for global type)
//this is an old function. was part of comparecode() before
//new parameter in comparecode make this function not required
//{toggle=false;}
/* MAIN */
int main(void)
{
//you can manually change the passwords below:
//future project implementation: save codes to file and access them
//but lose security if save to file?
//you can also customize this by adding more passwords, if you want to...
char *input1=new char[8],code1[8]="you",
*input2=new char[8],code2[8]="can't",
*input3=new char[8],code3[8]="pass",
*input4=new char[8],code4[8]="me";
bool toggle;
do
{
printf("you have at most (10) seconds to input all required code(s)\n");
//the start timer was here before but now moved to save that piece of time
printf("input security lock code 1: [");
//start timer here (incomplete)
inputcode(input1);
printf("input security lock code 2: [");
inputcode(input2);
printf("input security lock code 3: [");
inputcode(input3);
printf("input security lock code 4: [");
inputcode(input4);
//end timer here (incomplete)
//check value diffence between starttime and endtime
//if starttime minus endtime is greater than 10, then toggle = false
//else toggle = true
toggle=true; //set toggle to true
while(toggle)
{
if(!comparecode(input1,code1,toggle)){/*tofalse(toggle);*/break;}
if(!comparecode(input2,code2,toggle)){/*tofalse(toggle);*/break;}
if(!comparecode(input3,code3,toggle)){/*tofalse(toggle);*/break;}
if(!comparecode(input4,code4,toggle)){/*tofalse(toggle);*/break;}
break;
}
if(toggle)
{
delete[]input1;
delete[]input2;
delete[]input3;
delete[]input4;
printf("correct code\n");
return 0;
//option(); //menu
}
else //printf("incorrect code\n"); //can't think of anything to do yet
printf("invalid code\n");
//note: if the time exceeds 10 seconds and you entered the correct code,
//the application will recognize it as invalid
//this is good in a way as intruders have to guess
}while(!toggle);
return 0;
}
//end of source