C에서 암호 입력때 별표로 대신 출력하는 방법을 모르겠습니다.

kjw7945의 이미지

C 리눅스 환경에서

보통 암호 입력시 별표로 출력이 대신해서
나오는 것을 해보고 싶습니다.

scanf로는 안될 듯 싶네요.

그래서 알아보던 중에 다른 라이브러리를 쓰면 된다고 하는데

종류가 굉장히 많아서 잘 모르겠습니다. 현재 수준은

C 문법만 아는 정도 입니다. 아무튼...

어떤 라이브러리의 어떤 함수를 써야 하는지 알려주시면

감사하겠습니다. 지금 그 부분을 모르고 있습니다...

찬스의 이미지

int main()
{
printf("you input is (%s)\n", inputpass());
return 0;
}

#include <termios.h>
#include <stdio.h>

#define MAX_PASS_LEN 16
static char passwd[MAX_PASS_LEN];
static char *inputpass(void);

static char *inputpass(void)
{
char temp;
int i = 0;
struct termios old, new;

tcgetattr(fileno(stdin), &old);
new = old;
// 반향을 제거한다.
new.c_lflag =~ ECHO;
tcsetattr(fileno(stdin), TCSAFLUSH, &new);

printf("password ");
while((temp=getchar()) != '\n')
{
if (i == MAX_PASS_LEN) break;
passwd[i] = temp;
i++;
}
// 원래 터미널 상태로 되돌린다.
tcsetattr(fileno(stdin), TCSANOW, &old);
return passwd;
}

*^^*

익명 사용자의 이미지

getpass()라는 함수가 있습니다.

kjw7945의 이미지

위의 답변해주신 소스코드를
알려주셔서 감사드립니다...
프로그램을 만들어보고 싶어서
의욕이 넘칩니다...^^
프로그램을 만드는데 도움을 주셔서 감사합니다.