Use common bits/shm.h for more architectures.
[glibc.git] / manual / examples / testpass.c
blobf8883fea176fa74e841c2b0f54465a4a4c7328b4
1 /* Verify a passphrase.
2 Copyright (C) 1991-2018 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/>.
18 #include <stdio.h>
19 #include <string.h>
20 #include <unistd.h>
21 #include <crypt.h>
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";
29 int
30 main(void)
32 char *phrase;
33 int status = 0;
35 /* Prompt for a passphrase. */
36 phrase = getpass ("Enter passphrase: ");
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}. */
42 if (strcmp (crypt (phrase, hash_sha), hash_sha))
44 puts ("SHA: not ok");
45 status = 1;
47 else
48 puts ("SHA: ok");
50 if (strcmp (crypt (phrase, hash_md5), hash_md5))
52 puts ("MD5: not ok");
53 status = 1;
55 else
56 puts ("MD5: ok");
58 if (strcmp (crypt (phrase, hash_des), hash_des))
60 puts ("DES: not ok");
61 status = 1;
63 else
64 puts ("DES: ok");
66 return status;