ee65d9b0a85021eb1503838902184a755cc81c55
[ircu2.10.12-pk.git] / ircd / crypt / 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  */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <time.h>
9 #if HAVE_UNISTD_H
10 #include <unistd.h>
11 #endif
12 #include "../../config/setup.h"
13 #if STDC_HEADERS
14 # include <string.h>
15 #else
16 # ifndef HAVE_STRCHR
17 #  define strchr index
18 # endif
19 char *strchr();
20 #endif
21
22 extern char *getpass();
23
24 int main(int argc, char *argv[])
25 {
26   static char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
27   char salt[3];
28   char * plaintext;
29
30   if (argc < 2) {
31     srandom(time(0));           /* may not be the BEST salt, but its close */
32     salt[0] = saltChars[random() % 64];
33     salt[1] = saltChars[random() % 64];
34     salt[2] = 0;
35   }
36   else {
37     salt[0] = argv[1][0];
38     salt[1] = argv[1][1];
39     salt[2] = '\0';
40     if ((strchr(saltChars, salt[0]) == NULL) || (strchr(saltChars, salt[1]) == NULL))
41       fprintf(stderr, "illegal salt %s\n", salt), exit(1);
42   }
43
44   plaintext = getpass("plaintext: ");
45
46   printf("%s\n", crypt(plaintext, salt));
47   return 0;
48 }
49