Import of tac_plus.v8.tar.gz: 173206 bytes, md5:
[tac_plus.git] / generate_passwd.c
1 /* 
2    Copyright (c) 1995-1998 by Cisco systems, Inc.
3
4    Permission to use, copy, modify, and distribute this software for
5    any purpose and without fee is hereby granted, provided that this
6    copyright and permission notice appear on all copies of the
7    software and supporting documentation, the name of Cisco Systems,
8    Inc. not be used in advertising or publicity pertaining to
9    distribution of the program without specific prior permission, and
10    notice be given in supporting documentation that modification,
11    copying and distribution is by permission of Cisco Systems, Inc.
12
13    Cisco Systems, Inc. makes no representations about the suitability
14    of this software for any purpose.  THIS SOFTWARE IS PROVIDED ``AS
15    IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
16    WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17    FITNESS FOR A PARTICULAR PURPOSE.
18 */
19
20 /* Program to des encrypt a password like Unix 
21    It prompts for the password to encrypt. 
22    You can optionally supply a salt to verify a password.
23    Usage: a.out [salt]
24 */
25
26 #define NULL 0
27
28 main(argc, argv)
29 char **argv;
30 {
31     char *crypt();
32     char pass[25], *salt, buf[24];
33     char *result;
34     int n;
35     char *prompt = "Password to be encrypted: ";
36
37     salt = NULL;
38
39     if (argc == 2) {
40         salt = argv[1];
41     }
42
43     write(1, prompt, strlen(prompt));
44     n = read(0, pass, sizeof(pass));
45     pass[n-1] = NULL;
46
47     if (!salt) {
48         int i, r, r1, r2;
49
50         srand(time(0));
51
52         for(i=0; i <= 1; i++) {
53
54             r = rand();
55
56             r = r & 127;
57
58             if (r < 46)
59                 r += 46;
60
61             if (r > 57 && r < 65)
62                 r += 7;
63
64             if (r > 90 && r < 97) 
65                 r += 6;
66
67             if (r > 122)
68                 r -= 5;
69
70             if (i == 0)
71                 r1 = r;
72
73             if (i == 1)
74                 r2 = r;
75         }
76
77         sprintf(buf, "%c%c", r1, r2);
78         salt = buf;
79     }
80
81     result = crypt(pass, salt);
82
83     write(1, result, strlen(result));
84     write(1, "\n", 1);
85 }
86
87
88
89
90