2005-02-22 Roland McGrath <roland@redhat.com>
[glibc.git] / manual / examples / testpass.c
blob5bd616d2a0442b7f4a6cd561525c2cc424f7bb6b
1 #include <stdio.h>
2 #include <string.h>
3 #include <unistd.h>
4 #include <crypt.h>
6 int
7 main(void)
9 /* Hashed form of "GNU libc manual". */
10 const char *const pass = "$1$/iSaq7rB$EoUw5jJPPvAPECNaaWzMK/";
12 char *result;
13 int ok;
15 /*@group*/
16 /* Read in the user's password and encrypt it,
17 passing the expected password in as the salt. */
18 result = crypt(getpass("Password:"), pass);
19 /*@end group*/
21 /* Test the result. */
22 ok = strcmp (result, pass) == 0;
24 puts(ok ? "Access granted." : "Access denied.");
25 return ok ? 0 : 1;