a36493a63ebd48b6836be53cefce60bcd37fb6b5
[ircu2.10.12-pk.git] / tools / mkpasswd.c
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  * $Id$
5  */
6 #define _XOPEN_SOURCE
7 #define _XOPEN_VERSION 4
8 #define _XOPEN_SOURCE_EXTENDED
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <time.h>
13 #include <unistd.h>
14
15 int main(int argc, char *argv[])
16 {
17   static char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
18   char salt[3];
19   char * plaintext;
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