#include #include #include #include int main(int argc, char * argv[]) { struct spwd *entry; if (argc<3) { fprintf(stderr,"Usage: %s [username] [password]\n",argv[0]); exit(1); } entry = getspnam(argv[1]); if (!entry) { if (access("/etc/shadow",W_OK)!=0) fprintf(stderr,"You do not have permission to access to the shadow file.\n"); else fprintf(stderr,"Cannot find user '%s'.\n",argv[1]); exit(1); } if (!strcmp(crypt(argv[2],entry->sp_pwdp),entry->sp_pwdp)) { printf("Matches.\n"); } else printf("Does not match.\n"); exit(0); }