1/* Verify a passphrase.
2 Copyright (C) 1991-2022 Free Software Foundation, Inc.
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
15 along with this program; if not, see <https://www.gnu.org/licenses/>.
16*/
17
18#include <stdio.h>
19#include <string.h>
20#include <unistd.h>
21#include <crypt.h>
22
23/* @samp{GNU's Not Unix} hashed using SHA-256, MD5, and DES. */
24static const char hash_sha[] =
25 "$5$DQ2z5NHf1jNJnChB$kV3ZTR0aUaosujPhLzR84Llo3BsspNSe4/tsp7VoEn6";
26static const char hash_md5[] = "$1$A3TxDv41$rtXVTUXl2LkeSV0UU5xxs1";
27static const char hash_des[] = "FgkTuF98w5DaI";
28
29int
30main(void)
31{
32 char *phrase;
33 int status = 0;
34
35 /* Prompt for a passphrase. */
36 phrase = getpass (prompt: "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}. */
41
42 if (strcmp (crypt (phrase: phrase, salt: hash_sha), hash_sha))
43 {
44 puts (s: "SHA: not ok");
45 status = 1;
46 }
47 else
48 puts (s: "SHA: ok");
49
50 if (strcmp (crypt (phrase: phrase, salt: hash_md5), hash_md5))
51 {
52 puts (s: "MD5: not ok");
53 status = 1;
54 }
55 else
56 puts (s: "MD5: ok");
57
58 if (strcmp (crypt (phrase: phrase, salt: hash_des), hash_des))
59 {
60 puts (s: "DES: not ok");
61 status = 1;
62 }
63 else
64 puts (s: "DES: ok");
65
66 return status;
67}
68

source code of glibc/manual/examples/testpass.c