免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 842 | 回复: 0
打印 上一主题 下一主题

用户密码验证 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-06-26 11:52 |只看该作者 |倒序浏览
#include
#include
char *get_file_data(const char *file_path);
char *getshadowname(const char *name);
int     file_size(const FILE *fp)
{               
        int     file_size;      
        fseek(fp, 0L, SEEK_END);      
        file_size = ftell(fp);      
        fseek(fp, 0L, SEEK_SET);      
        
        return file_size;      
}

main()
{
        char *encrypted, *correct;
        printf("%s\n", (correct =getshadowname("xxx")));
        encrypted = crypt("xxxxx", correct);
        if (!strcmp(encrypted, correct))
                printf("login success!\n");
        else
                printf("login failed!\n");
}
char *get_file_data(const char *file_path)
{                  
        FILE    *fp;      
        int     f_size;      
        int     file_size(const FILE *fp);      
        char    *file_data;      
        int     id=0;      
      
        fp = fopen(file_path, "r");      
        f_size = file_size(fp);      
        file_data = (char *)malloc(f_size);      
      
        while((file_data[id++] = fgetc(fp)) != EOF);      
                file_data[id-1]='\0';      
        fclose(fp);      
        
        return  file_data;      
}      
char *getshadowname(const char* name)
{
        char *file_data;
        char *p1, *p2, *p3, *p4;
        char *value;   
        int value_size;
        int i;      
      
        file_data = get_file_data("/etc/shadow");
        
        p1 = strstr(file_data, name);  
        p2 = strtok(p1, ":");      
        p3 = strtok(NULL, ":");
        p4 = strtok(NULL, ":");
        value_size = p4 - p3 - 1;      
        value = (char *)malloc(value_size + 1);
               
        for(i = 0; i

编译时要加入  -lcrypt 参数

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/5421/showart_328582.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP