View Full Version : Portable Console Password Prompt

2nd March 2007, 05:27
How can I create a C++ Console application, compiled with GCC, portable to Linux and Windows, with a password prompt without echo (does not show the password as you type it)?

I would like something like those:
- with stars echo:

User: bob
Password: ******

- or without any echo at all

User: bob

I googled this for hours without finding any solution that were a Console application (usable with bash, dos, etc) compiled with GCC and portable to Windows and Linux.

2nd March 2007, 06:11
Well... you can't :) At least if you want it to be secure. Password prompters usually attach directly to the terminal or even bypass the interuption mechanisms present in the system (usually by using some system call, at least under Unix) to avoid keyloggers sniffing the password. If you don't care about security, you can use readline or ncurses libraries.

2nd March 2007, 23:29
You can't?

Can't you program this for both OS's separately and then use the preprocessor to select the right version at compile-time? Doesn't Qt do something similar in order to be OS independent?


// Windows code
// Linux code

I don't know the exact syntax.