PDA

View Full Version : Portable Console Password Prompt



vermarajeev
2nd March 2007, 06: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
Password:

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.

wysota
2nd March 2007, 07: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.

Michiel
3rd March 2007, 00: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?

Like:

#if WINDOWS
// Windows code
#else
// Linux code
#endif

I don't know the exact syntax.