Author: Bleep <tomh@inxpress.net>
[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 #define _XOPEN_SOURCE
6 #define _XOPEN_VERSION 4
7 #define _XOPEN_SOURCE_EXTENDED
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <time.h>
12 #include <unistd.h>
13
14 int main(int argc, char *argv[])
15 {
16   static char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
17   char salt[3];
18   char * plaintext;
19
20   if (argc < 2) {
21     srandom(time(0));           /* may not be the BEST salt, but its close */
22     salt[0] = saltChars[random() % 64];
23     salt[1] = saltChars[random() % 64];
24     salt[2] = 0;
25   }
26   else {
27     salt[0] = argv[1][0];
28     salt[1] = argv[1][1];
29     salt[2] = '\0';
30     if ((strchr(saltChars, salt[0]) == NULL) || (strchr(saltChars, salt[1]) == NULL))
31       fprintf(stderr, "illegal salt %s\n", salt), exit(1);
32   }
33
34   plaintext = getpass("plaintext: ");
35
36   printf("%s\n", crypt(plaintext, salt));
37   return 0;
38 }
39