]>
Commit | Line | Data |
---|---|---|
841785ba | 1 | /* Verify a passphrase. |
04277e02 | 2 | Copyright (C) 1991-2019 Free Software Foundation, Inc. |
d9a17c07 RM |
3 | |
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. | |
8 | ||
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. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
5a82c748 | 15 | along with this program; if not, see <https://www.gnu.org/licenses/>. |
d9a17c07 RM |
16 | */ |
17 | ||
63f791d3 GK |
18 | #include <stdio.h> |
19 | #include <string.h> | |
20 | #include <unistd.h> | |
21 | #include <crypt.h> | |
22 | ||
841785ba ZW |
23 | /* @samp{GNU's Not Unix} hashed using SHA-256, MD5, and DES. */ |
24 | static const char hash_sha[] = | |
25 | "$5$DQ2z5NHf1jNJnChB$kV3ZTR0aUaosujPhLzR84Llo3BsspNSe4/tsp7VoEn6"; | |
26 | static const char hash_md5[] = "$1$A3TxDv41$rtXVTUXl2LkeSV0UU5xxs1"; | |
27 | static const char hash_des[] = "FgkTuF98w5DaI"; | |
28 | ||
d9a17c07 | 29 | int |
63f791d3 GK |
30 | main(void) |
31 | { | |
841785ba ZW |
32 | char *phrase; |
33 | int status = 0; | |
34 | ||
35 | /* Prompt for a passphrase. */ | |
36 | phrase = getpass ("Enter passphrase: "); | |
37 | ||
38 | /* Compare against the stored hashes. Any input that begins with | |
39 | @samp{GNU's No} will match the DES hash, but the other two will | |
40 | only match @samp{GNU's Not Unix}. */ | |
63f791d3 | 41 | |
841785ba ZW |
42 | if (strcmp (crypt (phrase, hash_sha), hash_sha)) |
43 | { | |
44 | puts ("SHA: not ok"); | |
45 | status = 1; | |
46 | } | |
47 | else | |
48 | puts ("SHA: ok"); | |
d9a17c07 | 49 | |
841785ba ZW |
50 | if (strcmp (crypt (phrase, hash_md5), hash_md5)) |
51 | { | |
52 | puts ("MD5: not ok"); | |
53 | status = 1; | |
54 | } | |
55 | else | |
56 | puts ("MD5: ok"); | |
63f791d3 | 57 | |
841785ba ZW |
58 | if (strcmp (crypt (phrase, hash_des), hash_des)) |
59 | { | |
60 | puts ("DES: not ok"); | |
61 | status = 1; | |
62 | } | |
63 | else | |
64 | puts ("DES: ok"); | |
63f791d3 | 65 | |
841785ba | 66 | return status; |
63f791d3 | 67 | } |