* elf/Makefile (ld.so): Adjust the sed script to insert _begin in to
[glibc.git] / manual / examples / genpass.c
bloba7626dbed5032218e7e6ef56535e83cb19236598
1 #include <stdio.h>
2 #include <time.h>
3 #include <unistd.h>
4 #include <crypt.h>
6 int
7 main(void)
9 unsigned long seed[2];
10 char salt[] = "$1$........";
11 const char *const seedchars =
12 "./0123456789ABCDEFGHIJKLMNOPQRST"
13 "UVWXYZabcdefghijklmnopqrstuvwxyz";
14 char *password;
15 int i;
17 /* Generate a (not very) random seed.
18 You should do it better than this... */
19 seed[0] = time(NULL);
20 seed[1] = getpid() ^ (seed[0] >> 14 & 0x30000);
22 /* Turn it into printable characters from `seedchars'. */
23 for (i = 0; i < 8; i++)
24 salt[3+i] = seedchars[(seed[i/5] >> (i%5)*6) & 0x3f];
26 /* Read in the user's password and encrypt it. */
27 password = crypt(getpass("Password:"), salt);
29 /* Print the results. */
30 puts(password);
31 return 0;