the source is provided below. this is a low security password program. if you find any errors, loop holes, or have any suggestions on the program (ie: optimizations), please post a response. thanks.
oh yeah, the password is "this is a secret".
type in a space, tab, or enter/return after each word.
you need to type the 4 passwords within 10 seconds (shouldn't be hard to do).
Code:
// lock(code4,length8,time10) (_lock.cpp) version gds2002042115beta
// using MSDEV VSC++ 6.0 (Win32 Console Application)
#include<iostream.h>
#include<fstream.h>
//#include<stdlib.h>
//#include<stdio.h>
#include<conio.h>
#include<time.h>
short unsigned int i;
//void option() //removed; obselete
//{
// cout<<"enter configuration mode? (y/n)";
//}
void fillcode(int i)
{
for(i;i<8;i++)
{
cout<<"*";
}
cout<<"]"<<endl;
}
void inputcode(char*&x)
{
cout<<flush;
for(i=0;i<8;i++)
{
x[i]=char(getch());
cout<<"*"<<flush;
if(x[i]==char(13)||x[i]=='\t'||x[i]==' '){break;}
}
fillcode(++i);
}
void comparecode(const char*x,const char*y,bool&z)
{
for(i=0;i<8;i++)
{
if(x[i]==char(13)||x[i]=='\t'||x[i]==' '&&y[i]==NULL)
{z=true;break;}
if(x[i]!=y[i])
{z=false;break;}
}
}
int main(void)
{
ofstream file("_lock.log",ios::app);
char *input1=new char[8],code1[8]="this",
*input2=new char[8],code2[8]="is",
*input3=new char[8],code3[8]="a",
*input4=new char[8],code4[8]="secret";
bool toggle=false;
time_t start,stop;
while(!toggle)
{
cout<<"you have at most (10) seconds to input all required code(s)"<<endl;
time(&start);
cout<<"input security lock code 1: [";inputcode(input1);
cout<<"input security lock code 2: [";inputcode(input2);
cout<<"input security lock code 3: [";inputcode(input3);
cout<<"input security lock code 4: [";inputcode(input4);
time(&stop);
file<<asctime(localtime(&start))<<endl
<<input1<<endl<<input2<<endl<<input3<<endl<<input4<<endl;
if(difftime(stop,start)<11)
{
comparecode(input1,code1,toggle);
if(!toggle){toggle=false;break;}
comparecode(input2,code2,toggle);
if(!toggle){toggle=false;break;}
comparecode(input3,code3,toggle);
if(!toggle){toggle=false;break;}
comparecode(input4,code4,toggle);
if(!toggle){toggle=false;break;}
}
if(toggle)
{
delete[]input1;
delete[]input2;
delete[]input3;
delete[]input4;
cout<<"correct code"<<endl;
//option(); //obselete
i=NULL;
toggle=NULL;
file<<endl;
file.close();
return 0;
}
else
{
cout<<"invalid code"<<endl;
}
} //while
return 0;
}
//end of source