C/C++ reading passwords

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi, I’m writing a program and I need to read some password, so I use
getpass, but later reading the man page of getpass I see “This function
is obsolete. Do not use it.”, so, what function can I use instead of
getpass?


VampirD

Microsoft Windows is like air conditioning
Stops working when you open a window.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/

iEYEARECAAYFAkykzLMACgkQJQ+0ABWtaVlqDACfUrMVtw6imrroERcilIjEE0D5
WU0AoKNaBvLdpS4ntBSoJASGzSd6lCBp
=r9Ew
-----END PGP SIGNATURE-----

There is no ready replacement available. You can easily one with getch().

Hi,

as far as I know you can use the header termios.h to set the echo flags. You can find an example on C/C++ Forum :: kein echo bei eingabe

Hope this helps

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I’ll have to code a bit more to do that :frowning:


VampirD

Microsoft Windows is like air conditioning
Stops working when you open a window.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/

iEYEARECAAYFAkyk6+4ACgkQJQ+0ABWtaVlV+QCfcGtnXamUov0qYa74GIFZFJlf
mOQAn05DRuiNi+tGSOMosydXxEJ3+r7b
=IpIs
-----END PGP SIGNATURE-----

It is used more for kinda advance terminal interfaces, but I think it’s worthy NCURSES Programming HOWTO

The idea is to implement a POSIX equivalent of getch(). This can be easily done by switching off the terminal buffering and then, using the getchar() or other functions. (Have a look at the code link suggested by Monex).