home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / pty4 / part02 / lock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-18  |  990 b   |  51 lines

  1. /* lock.c: clone of lock program
  2. Daniel J. Bernstein, brnstnd@nyu.edu.
  3. No dependencies.
  4. Requires curses and signal, i.e., UNIX.
  5. 7/27/91: Baseline. lock 2.0, public domain.
  6. No known patent problems.
  7.  
  8. Documentation in lock.1.
  9.  
  10. Derived from version of lock included with pty 3.0.
  11. */
  12.  
  13. #include <curses.h>
  14. #include <signal.h>
  15.  
  16. main()
  17. {
  18.  char key[100];
  19.  char key2[100];
  20.  int i;
  21.  
  22.  for (i = 1;i < 32;++i) /*XXX*/
  23.    signal(i,SIG_IGN);
  24.  savetty();
  25.  crmode();
  26.  noecho();
  27.  printf("Key: "); fflush(stdout);
  28.  if (fgets(key,sizeof(key) - 2,stdin))
  29.   {
  30.    printf("\nAgain: "); fflush(stdout);
  31.    if (fgets(key2,sizeof(key2) - 2,stdin))
  32.      if (!strcmp(key,key2))
  33.       {
  34.        printf("\n"); fflush(stdout);
  35.        while ((fgets(key2,sizeof(key2),stdin) == NULL) || strcmp(key,key2))
  36.     {
  37.      printf("Bad password!\n");
  38.      for (i = 0;i < 20;++i)
  39.        putchar(7);
  40.      fflush(stdout);
  41.      sleep(1);
  42.     }
  43.       }
  44.      else printf("\n%c",7);
  45.    else printf("\n%c",7);
  46.   }
  47.  else printf("\n%c",7);
  48.  resetty();
  49.  exit(0);
  50. }
  51.