Solaris7 交流 --- 程序生成系统用户方法(crypt)

王朝other·作者佚名  2006-11-24
宽屏版  字体: |||超大  

六、程序生成系统用户方法(crypt)

crypt是个密码加密函数,它是基於Data Encryption Standard(DES)演算法。

crypt基本上是One way encryption,因此它只适用於密码的使用,不适合於资料加密

char *crypt(const char *key, const char *salt);

key是使用者的密码。salt是两个字,每个字可从[a-zA-Z0-9./]中选出来,因此同一密

码增加了4096种可能性。透过使用key中每个字的低七位元,取得56-bit关键字,这

56-bit关键字被用来加密成一组字,这组字有13个可显示的 ASCII字,包含开头两个

salt。 crypt在您有自行管理使用者的场合时使用,例如会员网站、BBS等等。

范例一 : crypt_word.c

#include

#include

#include

void main(int argc,char **argv)

{

if (argc!=3) exit(0);

setkey(argv[2]);

printf("%s\n",crypt(argv[1],argv[2]));

}

编译

gcc -o crypt_word crypt.c -lcrypt

检验

请先看您的/etc/passwd,找一个您自己的帐号,看前面两个字,那是您自己的salt。

接下来输入: ./crypt_word your_password salt

您也可以利用Apache上所附的htpasswd来产生加密字做为验证。

fprintf(f_passwd,"%s:x:%d:%s::%s/%s:/bin/sh\n",get_name,get_uid,sUserGrou

p,get_path,get_name);

setkey("O7");

get_password1=get_password;

get_password1=crypt(get_pass,"O7");

fprintf(f_shadow,"%s:%s:10000::::::\n",get_name,get_password1);

sprintf(sys_str,"mkdir %s/%s",get_path,get_name);

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有