test-checkpw.c
1 2 3 #include <security/checkpw.h> 4 #include <pwd.h> 5 #include <stdio.h> 6 #include <string.h> 7 #include <unistd.h> 8 9 const char *prompt = "checkpw test prompt:"; 10 11 int 12 main(int argv, char *argc[]) 13 { 14 char *uname; 15 int retval = 0; 16 struct passwd *pw = NULL; 17 18 uname = (char*)getenv("USER"); 19 if ( NULL == uname) 20 { 21 uid_t uid = getuid(); 22 struct passwd *pw = getpwuid(uid); 23 uname = pw->pw_name; 24 } 25 26 retval = checkpw(uname, getpass(prompt)); 27 if (0 == retval) 28 { 29 printf("Password is okay.\n"); 30 } else { 31 printf("Incorrect password.\n"); 32 } 33 34 return retval; 35 }