1 /* Encrypting Passwords
2 Copyright (C) 1991-2015 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, if not, see <http://www.gnu.org/licenses/>.
26 unsigned long seed
[2];
27 char salt
[] = "$1$........";
28 const char *const seedchars
=
29 "./0123456789ABCDEFGHIJKLMNOPQRST"
30 "UVWXYZabcdefghijklmnopqrstuvwxyz";
34 /* Generate a (not very) random seed.
35 You should do it better than this... */
37 seed
[1] = getpid() ^ (seed
[0] >> 14 & 0x30000);
39 /* Turn it into printable characters from `seedchars'. */
40 for (i
= 0; i
< 8; i
++)
41 salt
[3+i
] = seedchars
[(seed
[i
/5] >> (i
%5)*6) & 0x3f];
43 /* Read in the user's password and encrypt it. */
44 password
= crypt(getpass("Password:"), salt
);
46 /* Print the results. */