[Linux C] 實做讀取密碼(password)功能

[Linux C] 實做讀取密碼(password)功能

[Linux C] 實做讀取密碼(password)功能


因為昨天po了一篇java讀取密碼功能,所以找了一下Linux C的版本,趕緊和同好分享。

#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
void SetStdinEcho(int intenable)
{
struct termios tty;
tcgetattr(STDIN_FILENO, &tty);
if( intenable==0 )
tty.c_lflag &= ~ECHO;
else
tty.c_lflag |= ECHO;
(void) tcsetattr(STDIN_FILENO, TCSANOW, &tty);
}
int main()
{
char show[80],hide[80];
SetStdinEcho(1);
printf("input pawssword:\n");
scanf("%s",show);
printf("show_pawssword:%s\n",show);
SetStdinEcho(0);
printf("input pawssword:\n");
scanf("%s",hide);
printf("hide_pawssword:%s\n",hide);
SetStdinEcho(1);
return 0;
}

 

 

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *