Back to index

glibc  2.9
testpass.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 #include <unistd.h>
00004 #include <crypt.h>
00005 
00006 int 
00007 main(void)
00008 {
00009   /* Hashed form of "GNU libc manual".  */
00010   const char *const pass = "$1$/iSaq7rB$EoUw5jJPPvAPECNaaWzMK/";
00011 
00012   char *result;
00013   int ok;
00014   
00015 /*@group*/
00016   /* Read in the user's password and encrypt it,
00017      passing the expected password in as the salt.  */
00018   result = crypt(getpass("Password:"), pass);
00019 /*@end group*/
00020 
00021   /* Test the result.  */
00022   ok = strcmp (result, pass) == 0;
00023 
00024   puts(ok ? "Access granted." : "Access denied.");
00025   return ok ? 0 : 1;
00026 }