I could use getpass()
to get a password. However, the man page says:
This function is obsolete. Do not use it.
What is the current way to get a password from the user's terminal without echoing it, in a POSIX-compliant way? [Originally I said "portably", but my intention was to avoid using an obsolete function.]
this should work on linux/macosx, a windows version should use Get/Set ConsoleMode
On windows, you can probably use the
SetConsoleMode
api, described here.Even though this is a very old question that has already been answered, here's what I've been using (which is very similar to the accepted answer):
You could use the ncurses library to read from standard input without echoing the results to the screen. (Call
noecho()
before getting any input). The library has been around for ages and works on a wide variety of platforms (the windows version can be found here)According to the University of Milwaukee's documentation it is obsolete because: