home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 2: Collection B / 17Bit_Collection_B.iso / files / 1280.dms / in.adf / PASS / pass.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-14  |  1.4 KB  |  85 lines

  1. /* This program will ask for a password from the user.
  2.    if the password is incorrect the program goes round
  3.    again. */
  4.  
  5. #include <string.h>
  6. #include <stdio.h>
  7.  
  8. /* The main function */
  9.  
  10. void main()
  11. {
  12.    char c,input[10],pass[10];
  13.    char *p_pass,*p_input;
  14.    int counter,result;
  15.  
  16.    /* Call the routine to read the password from disk */
  17.  
  18.    readpass(pass);
  19.    p_pass=pass;
  20.    p_input=input;
  21.  
  22.    /* The main program loop. Waits for the correct password */
  23.  
  24.    do
  25.    {
  26.       counter=0;
  27.       input[0]='\0';
  28.  
  29.       printf("\33cPlease enter the password:\n\33[8m");
  30.  
  31.       /* Get the users input */
  32.  
  33.       do
  34.       {
  35.          c=getchar();
  36.          input[counter]=c;
  37.          ++counter;
  38.       }
  39.       while(c!='\n' && counter!=10);
  40.       input[counter-1]='\0';
  41.       printf("\33[0m");
  42.  
  43.       /* Check the two strings. result=0 means same. */
  44.  
  45.       result=strcmp(p_pass,p_input);
  46.    }
  47.    while(result!=0);
  48. }
  49.  
  50. /* The routine to read the 'word' file containing the password */
  51.  
  52. int readpass(got)
  53.  char got[10];
  54. {
  55.    FILE *in_file, *fopen();
  56.    int c,count;
  57.    count=0;
  58.  
  59.    /* Open the file */
  60.  
  61.    in_file=fopen("word","r");
  62.    if(in_file==NULL)
  63.    {
  64.       printf("Sorry there is no password file!\n");
  65.       exit(0);
  66.    }
  67.    else
  68.    {
  69.  
  70.       /* Read the password */
  71.  
  72.       while((c=getc(in_file))!=EOF)
  73.       {
  74.          got[count]=c;
  75.          ++count;
  76.       }
  77.  
  78.    /* Return the password to the main() function and
  79.       end the routine */
  80.  
  81.    got[count-1]='\0';
  82.    return(got);
  83.    }
  84. }
  85.