help add implements to this beta array/vector comparison program

This is a discussion on help add implements to this beta array/vector comparison program within the C++ Programming forums, part of the General Programming Boards category; /* okay, I have started on a simple project that will request for a password every time my computer is ...

  1. #1
    Registered User toaster's Avatar
    Join Date
    Apr 2002
    Posts
    161

    help add implements to this beta array/vector comparison program

    /*
    okay, I have started on a simple project that will request for a password every time my computer is turned on. the code is shown below. I am using windows and I want to know how to make this program run first before windows begin. also, if you have any suggestions or comments on this program or would like to add something onto this source, please feel free to do so. you don't necessarily have to provide code but ideas are good enough. also, this message will be continued to be modified after certain implementations.
    */

    Code:
    //#include<stdlib.h>
    #include<stdio.h>
    #include<conio.h>
    int main(void)
    {
     //initializations
     char input[8],code[8]="code";
     int i;
     bool check=true;
    
     do
     {
     printf("password: [");
     input=NULL; //resets input
    
     //user enters password
     for(i=0;i<8;i++)
     {
      input[i]=getch();
      printf("*");
      fflush(stdout);
      if(input[i]==char(13)){break;}
     }
     printf("]");
    
     //custom string comparison (so I don't have to use strcmp() )
     check=true;
     for(i=0;i<8;i++)
     {
      if(input[i]==char(13))
      {
       if(code[i]==char(0)){break;}
      }
      if(input[i]!=code[i]){check=false;break;}
     }
     if(check){printf("correct password");return 0;}
     else printf("incorrect password");
     }while(!check)
     //return 0;
    }
    the code below is modified using functions calls

    Code:
    //#include<stdlib.h> // for system()
    #include<stdio.h>
    #include<conio.h> // for getch()
    //#include<time.h>
    
    /*GLOBAL*/
    short unsigned int i; //trying to save some memory
    
    void fillcode(int i)
    {
     for(i;i<8;i++)
     {
      printf("*");
     }
     printf("] ");
    }
    
    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;}
     }
     fillcode(i++);
    }
    
    int main(void)
    {
     bool toggle;
     char *input1=new char[8],code1[8]="code";
    
     //future implementation: add time limit
     //printf("you have at most (10) seconds to input all code(s)\n");
    
     do
     {
     printf("input security lock code: [");
     inputcode(input1);
    /* //this is replaced by a function
     for(i=0;i<8;i++)
     {
      input[i]=getch();
      printf("*");
      fflush(stdout);
      if(input[i]==char(13)){break;}
     }
     printf("]");
    */
    
     toggle=true; //set toggle
     for(i=0;i<8;i++) //custom string compare code segment
     {
      if( (input1[i]==char(13)) || (input1[i]==' ') && (code1[i]==char(0)) ){break;}
      if(input1[i]!=code1[i]){toggle=false;break;}
     }
     if(toggle)
     {
      delete[]input1;
      printf("correct code\n");
      return 0;
     }
     else printf("incorrect code\n");
     }while(!toggle);
     return 0;
    }
    Last edited by toaster; 04-20-2002 at 02:12 PM.
    think only with code.
    write only with source.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    One suggestion and one question. Why not simply place the exe in the startup folder so that the program is automatically run when Windows is finished booting up. You can add code that denies the user any other action except to enter the password so no problem there.

    What do you plan to do if the user enters the incorrect password or does so continuously? You should do something besides simply print "Incorrect password". Perhaps reboot upon 3 invalid tries.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User toaster's Avatar
    Join Date
    Apr 2002
    Posts
    161
    hmm, reboot after 3 tries? I don't know. Since I want this program to start before windows, I do have to add a command prompt to some windows configuration file (win.ini ?).
    so far the [ Ctrl + C ] combo fails, hopefully.
    does anyone know what file I have to add the prompt to?
    think only with code.
    write only with source.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    200
    you can add it to autoexec.bat or autoexec.nt file if you like.
    I go to encounter for the millionth time the reality of experience and to forge in the smithy of my soul the uncreated conscience of my race.

    Windows XP consists of 32 bit extensions and a graphical shell for a 16 bit patch to an 8 bit operating system originally coded for a 4 bit microprocessor, written by a 2 bit company, that can't stand 1 bit of competition.

  5. #5
    Registered User toaster's Avatar
    Join Date
    Apr 2002
    Posts
    161
    in the autoexec.* file, do I just call the program directory?

    example:

    C:\lock.exe

    and are there any risks in calling this program in autoexec?
    think only with code.
    write only with source.

  6. #6
    Registered User toaster's Avatar
    Join Date
    Apr 2002
    Posts
    161
    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
    Last edited by toaster; 04-20-2002 at 04:39 PM.
    think only with code.
    write only with source.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. trying to add a sum function in a class program - help
    By dkhurl in forum C++ Programming
    Replies: 3
    Last Post: 01-13-2009, 02:49 AM
  2. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  3. add your program to start menu ?
    By Anddos in forum Windows Programming
    Replies: 6
    Last Post: 04-17-2008, 05:15 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21