#include
#include
#include
#include
int verify_passwd(char *id, char *passwd)
{
struct spwd *sp;
if(!(id && passwd)) {
printf("param error");
return -1;
}
sp = getspnam(id);
if(sp == NULL) {
printf("get spentry error\n");
return -1;
}
if(strcmp(sp->sp_pwdp, (char*)crypt(passwd, sp->sp_pwdp)) == 0) {
printf("passwd yes\n");
} else {
printf("passwd error\n");
}
return 0;
}
int main()
{
char id[32] = "";
char *passwd;
printf("Login: ");
scanf("%s", id);
passwd = getpass("Enter the password:");
verify_passwd(id, passwd);
return 0;
}
编译加上 -lcrypt