linux c语言密码验证

Posted 吾乃世间奇才

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux c语言密码验证相关的知识,希望对你有一定的参考价值。

#include <stdio.h>
#include <string.h>
#include <shadow.h>
#include <unistd.h>
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

以上是关于linux c语言密码验证的主要内容,如果未能解决你的问题,请参考以下文章