1

is it possible to do an invisible input like the password prompt under linux when entering the password?

I mean, when I use scanf that the chars just don't show up? Or at least are empty spaces? So that the user doesn't see what he types.

I've googled it but I didn't found any question or approach that went into this direction. Maybe someone can at least tell me if it's even possible with c or maybe also give me a hint how.

Regards

Michael Brenndoerfer
  • 3,483
  • 2
  • 39
  • 50
  • You need to turn off "terminal echo". see http://stackoverflow.com/questions/5633472/how-do-i-turn-off-echo-in-a-terminal – Jan Matějka Jan 02 '14 at 22:35
  • 1
    What platform are you using? For windows, you should use `CredUICmdLinePromptForCredentials` – josh poley Jan 02 '14 at 23:08
  • Yes, I'm using windows but it has to work also under linux and I'm not allowed to use any other includes beside stdio. But thanks for the hint. It seems to be the most correct way. :) – Michael Brenndoerfer Jan 02 '14 at 23:12

1 Answers1

2

Thanks for your suggestions. There really was an answer which helped me. Finally I've done it like that:

void inputPassword(){

char pass[20];
printf("Password: ");

int i = 0;
while ((pass[i] = getch()) != '\n' && pass[i] != '\r' && i < 19){
    putchar(' ');
    i++;
}

pass[i] = '\0';

}
Michael Brenndoerfer
  • 3,483
  • 2
  • 39
  • 50