Do not use libcore/base.h anymore in this library.
[AROS.git] / tools / crypt.c
blobf08785a72edfa69bfb8c7d2692e3a3bfa385017f
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Utility for crypt(3).
6 Lang: english
7 */
9 /*
10 This is the sourcecode for crypt. It is a small program which makes
11 it more convenient to create Unix passwords with crypt(3).
13 To compile:
15 cc crypt.c -o crypt
17 If you get an error during link which says that "crypt" is an
18 unknown symbol, try this:
20 cc crypt.c -o crypt -lcrypt
22 Then run this with your password as the first argument. If you
23 want to test if it really works, try it like this:
25 crypt test xx
27 which must print:
29 Encrypting test: xx1LtbDbOY4/E
31 If it prints something else, then your version of crypt(3) is not
32 compatible.
35 #define _XOPEN_SOURCE
36 #include <unistd.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <time.h>
41 int main (int argc, char ** argv)
43 char salt[3];
44 char set[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
47 if (argc < 2 || argc > 3)
49 printf("Usage: %s <password> [<salt>]\n", argv[0]);
50 return 1;
53 srand (time (NULL));
55 salt[0] = set[getpid() % sizeof(set)];
56 salt[1] = set[rand() % sizeof(set)];
57 salt[2] = 0;
59 if (argc > 2)
61 salt[0] = argv[2][0];
62 salt[1] = argv[2][1];
65 printf ("Encrypting %s: %s\n", argv[1], crypt (argv[1], salt));
67 return 0;