For password input, Is there a way in ansi c to stop input being echoed?
I would ideally like to do it platform independantly, any help would be great.
:)
Printable View
For password input, Is there a way in ansi c to stop input being echoed?
I would ideally like to do it platform independantly, any help would be great.
:)
Not in ANSI C. No. There is no portable way to do this. It is all system dependant.
Quzah.
like quzah said, there's no portable way. On *nix with curses/ncurses you can use noecho(); to disable charater echo at input.
Like others said, there is no ANSI response. But there is a POSIX one: getpass(). Many platforms are POSIX compliant (well, part of, because POSIX is BIG).Quote:
Originally Posted by Kinasz
Emmanuel, from my man page on getpass():
Code:NAME
getpass - get a password
SYNOPSIS
#include <unistd.h>
char *getpass( const char * prompt );
DESCRIPTION
This function is obsolete. Do not use it.
The getpass() function opens /dev/tty
(the controlling terminal of the process), outputs the string
prompt, turns off echoing, reads one line
(the "password"), restores the terminal state and closes
/dev/tty again.
Yes. It sounds that the correct functions belong toQuote:
Originally Posted by viaxd
fgetpwent()
getpwnam()
getpwuid()
getpw()
putpwent()
passwd()
But i'm not sure there are POSIX.... More UNIX/BSD...
There's a Windows way to do it also, but it requires you to install a *nix based OS...
Quzah.
ok guys thanks for your answers, I think I will look into cursers and worry about getting it work with other platforms when the need arises
bit of a shame ansi doesnt do it
It's clearly a system issue. Getting the password is a part of the user identifier system. If it wasn't part of the system, it would be too easy to abuse it.Quote:
Originally Posted by Kinasz
but the only purpose of not echoing is making sure the password doesnt remain on the screen and appear in the history, surely ansi could have defined "no echo" ?Quote:
It's clearly a system issue. Getting the password is a part of the user identifier system. If it wasn't part of the system, it would be too easy to abuse it.
Standard C doesn't require there to be a screen, so what would this "no echo" really do when applied to a stream? What if the stream were redirected to a file? Even if you answer those questions successfully, what if the system didn't support a quick and easy way to turn off echoing? The standard committee probably would have discussed it and concluded that it was impossible to come up with a portable definition of such a feature.Quote:
Originally Posted by Kinasz
Bare in mind that in standard C, the input stream is stdin. It could be connected to any physical device. What is an 'echo' for a barcode reader, a scanner or even a keyboard? The 'echo' function is a system feature that makes sense only when the input and output and attached to some console which is just another possibility.Quote:
Originally Posted by Kinasz