unix下取得加密的用戶密碼
我們知道unix的用戶信息要不然放在/etc/passwd,要不放在/etc/shadow中在ubuntu中寫一個比較密碼的程序:
#define _XOPEN_SOURCE #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <shadow.h> #include <pwd.h> 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的方式鳥。
最後更新:2017-04-04 07:04:13