home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / in4wjcxu / other / irc / ircd / crypt / mkpasswd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-14  |  956 b   |  41 lines

  1. /* simple password generator by Nelson Minar (minar@reed.edu)
  2.  * copyright 1991, all rights reserved.
  3.  * You can use this code as long as my name stays with it.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <unistd.h>
  8. #include <strings.h>
  9.  
  10. extern char *getpass();
  11.  
  12. int main(argc, argv)
  13. int argc;
  14. char *argv[];
  15. {
  16.   static char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
  17.   char salt[3];
  18.   char * plaintext;
  19.   int i;
  20.  
  21.   if (argc < 2) {
  22.     srandom(time(0));        /* may not be the BEST salt, but its close */
  23.     salt[0] = saltChars[random() % 64];
  24.     salt[1] = saltChars[random() % 64];
  25.     salt[2] = 0;
  26.   }
  27.   else {
  28.     salt[0] = argv[1][0];
  29.     salt[1] = argv[1][1];
  30.     salt[2] = '\0';
  31.     if ((strchr(saltChars, salt[0]) == NULL) || (strchr(saltChars, salt[1]) == NULL))
  32.       fprintf(stderr, "illegal salt %s\n", salt), exit(1);
  33.   }
  34.  
  35.   plaintext = getpass("plaintext: ");
  36.  
  37.   printf("%s\n", crypt(plaintext, salt));
  38.   return 0;
  39. }
  40.  
  41.