您当前的位置: 首页 >  unix

unix下取得加密的用户密码

发布时间:2013-02-28 16:03:24 ,浏览量:0

    我们知道unix的用户信息要不然放在/etc/passwd,要不放在/etc/shadow中

在ubuntu中写一个比较密码的程序:

#define _XOPEN_SOURCE
#include 
#include 
#include 
#include 
#include 

int main(int argc,char **argv)
{
	if(argc!=2){
		printf("usage : %s user_namen",argv[0]);
		exit(-1);
	}
	
	struct passwd *pwd = getpwnam(argv[1]);
	printf("%s pwd is %sn",argv[1],pwd->pw_passwd);
	
	struct spwd *spwd = getspnam(argv[1]);
	printf("%s pwd is %sn",argv[1],spwd->sp_pwdp);
	
	char *pwd_in = getpass("passwd:");
	char *epwd = crypt(pwd_in,spwd->sp_pwdp);
	printf("%s epwd is %sn",argv[1],epwd);
	
	return 0;
}
    以上代码在mac os X 10.x后无效,貌似必须采用mac api或者PAM的方式鸟。     

    

关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    108252博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.3248s