home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / c / cc03.arc / MODPASS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1985-08-28  |  4.8 KB  |  119 lines

  1. /**
  2. * modpass.c
  3. *
  4. * Allow the Password in the file PASSWD.COM to be Changed
  5. * This program will first read in the ENTIRE PASSWD.COM file
  6. * and extract the six (6) characters of the password.
  7. * The Password MUST be retyped exactly to be changed.
  8. * The PASSWD.COM file is then written back out to the disk.
  9. * This program will display all of the keyed characters and passwords
  10. *
  11. * I apologize for this not being a "clear" piece of 'C' code
  12. * but strings and I are still having problems.
  13. *
  14. * This program was written using Lattice ver 2.14 'C' Compiler
  15. *  Garth Kennedy    26 December 1984
  16. **/
  17. #include "_main.c"
  18.  
  19. main()
  20. {
  21.     static char pass[300];   /* data file for PASSWRD.COM */
  22.     static char *passf = "PASSWRD.COM"; /* file name */
  23.     char *p;                 /* pointer to first block of data */
  24.     FILE *fp;                /* file pointer */
  25.     int nact;                /* number of blocks read/written */
  26.     int n;                   /* number of blocks to be read/written */
  27.     int s;                   /* size of each block, in bytes */
  28.     char *mode = "rb+";        /* read/write a file -untranslated */
  29.     int ret;                  /* return code */
  30.     static char pw1[10],pw2[10];   /* temp holding for new passwords */
  31.     int i,j,k,l;
  32.     char c,d;
  33.      
  34.     s = 0xFE;                /* size of PASSWRD.COM */
  35.     n = 1;                   /* one block to be read */
  36.     p = &pass[0];            /* pointer to beginning of data file */
  37.     fp = fopen(passf,mode);    /* open the file */
  38.     nact = fread(p,s,n,fp);     /* read data block from disc */
  39.     ret = fclose(fp);       /* close the disc file */  
  40.  
  41.                      /* Print out the CRT Header */
  42.     printf("   Change the Password Program               26 Dec 1984\n\n");
  43.     printf("         This program is in the public domain, the program may\n");
  44.     printf("         be copied and used without charge.\n");
  45.     printf("                   Copyright  KJ Consulting 1984\n\n");
  46.  
  47.     printf("\n       This program will allow the password to be changed\n");
  48.     printf("\n       in the password program PASSWRD.COM.\n"); 
  49.     printf("\n       You will be asked to 1.) Enter the current Password\n");
  50.     printf("                            2.) Enter the New Password\n");
  51.     printf("                            3.) Reenter the New Password\n");
  52.     printf("\n       ");  
  53.     printf("\n       At any point at which the Passwords dont match this program\n");
  54.     printf("       will terminate\n\n\n");
  55.  
  56.     pw1[0] = pass[0xAC],pw1[1] = pass[0xB1],pw1[2] = pass[0xB6];
  57.     pw1[3] = pass[0xBB],pw1[4] = pass[0xC0],pw1[5] = pass[0xC5]; 
  58.  
  59.     printf("The current Password is - ");
  60.     printf("%c%c%c%c%c%c\n",pw1[0],pw1[1],pw1[2],pw1[3],pw1[4],pw1[5]);
  61.     printf("The Password in HEX Notation is ");
  62.     printf("%x %x %x %x %x %x\n",pw1[0],pw1[1],pw1[2],pw1[3],pw1[4],pw1[5]);
  63.  
  64.     i = 0,j = 0,l = 0;
  65.     printf("Please enter the Current Password (6 characters) - ");
  66.     for (i = 0;i <= 5;i++)       /* manually enter to confirm */
  67.     {
  68.         c = getch();         /* check char by char */
  69.         if (c != pw1[i])     /* j will be non-zero if wrong */
  70.             j++;
  71.         printf("%c",c);
  72.     }
  73.     printf("\n");
  74.     if (j != 0 )                /* didnt match */ 
  75.     {
  76.         printf("\n\n  !!! SORRY !!!  Wrong Password Entered \n\n");
  77.         exit(); 
  78.     }
  79.     while (l == 0)
  80.     {
  81.         printf("\nPlease Enter the New Password. Exactly Six (6) Characters - ");
  82.         for (i = 0;i <= 5;i++)
  83.         {
  84.             pw2[i] = getch();
  85.             printf("%c",pw2[i]);
  86.         }
  87.         printf("\n");
  88.         
  89.         j = 0;
  90.         printf("Please Reenter the New Password (6 characters) - ");
  91.         for (i = 0;i <= 5;i++)       /* manually enter to confirm */
  92.         {
  93.             c = getch();             /* check reentry char by char */
  94.             if (c != pw2[i])  j++;   /* j non-zero if no match */
  95.             printf("%c",c);
  96.         }
  97.         printf("\n");
  98.         if (j == 0)
  99.             l = 999;            /* new password checks */
  100.     }                          /* end of if l == 0 */
  101.                         /* if j non-zero repeat the whole new password */
  102.                         /* entry - vlaues will need to be reentered */
  103.  
  104.     printf("Saving the new Password\n\n");  /* passwords matched */
  105.     pass[0xAC] = pw2[0],pass[0xB1] = pw2[1],pass[0xB6] = pw2[2];
  106.     pass[0xBB] = pw2[3],pass[0xC0] = pw2[4],pass[0xC5] = pw2[5]; 
  107.  
  108.     s = 0xFE;                /* size of PASSWRD.COM */
  109.     n = 1;                   /* one block to be read */
  110.     p = &pass[0];            /* pointer to beginning of data file */
  111.     fp = fopen(passf,mode);    /* open the file */
  112.     nact = fwrite(p,s,n,fp);     /* read data block from disc */
  113.     ret = fclose(fp);       /* close the disc file */  
  114.  
  115.     exit();
  116. }
  117.  
  118.