Chinaunix

标题: linux下实现getpass? [打印本页]

作者: aldslvda    时间: 2013-09-09 08:49
标题: linux下实现getpass?
  1. #include<unistd.h>
  2. #include<stdio.h>
  3. #include<conio.h>
  4. #include<string.h>
  5. int main()
  6. {
  7. char passwd[13];
  8. char *key;
  9. char slat[2];
  10. key= getpass(“Input First Password:”);
  11. slat[0]=key[0];
  12. slat[1]=key[1];
  13. strcpy(passwd,crypt(key slat));
  14. key=getpass(“Input Second Password:”);
  15. slat[0]=passwd[0];
  16. slat[1]=passwd[1];
  17. printf(“After crypt(),1st passwd :%s\n”,passwd);
  18. printf(“After crypt(),2nd passwd:%s \n”,crypt(key slat));
  19. }
复制代码
本来是想实现这样的程序
后来发现conio.h在linux下没有
有什么替代的方法吗?
作者: flyingeagle1015    时间: 2013-09-09 09:23
拿你的代码改了下,可以运行。
#define _XOPEN_SOURCE
#include<unistd.h>
#include<stdio.h>
//#include<conio.h>
#include<string.h>
int main()
{
char passwd[13];
char *key;
char slat[2];
key= getpass("input First Password);
slat[0]=key[0];
slat[1]=key[1];
strcpy(passwd,crypt(key,slat));
key=getpass("Input Second Password:";
slat[0]=passwd[0];
slat[1]=passwd[1];
printf("After crypt(),1st passwd :%s\n",passwd);
printf("After crypt(),2nd passwd:%s \n",crypt(key,slat));




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2