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.
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.
"Assumptions are the mother of all **** ups!"
Not in ANSI C. No. There is no portable way to do this. It is all system dependant.
Quzah.
Hope is the first step on the road to disappointment.
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).Originally Posted by Kinasz
Last edited by Emmanuel Delaha; 07-25-2004 at 05:35 AM. Reason: typo
Emmanuel Delahaye
"C is a sharp tool"
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 toOriginally Posted by viaxd
fgetpwent()
getpwnam()
getpwuid()
getpw()
putpwent()
passwd()
But i'm not sure there are POSIX.... More UNIX/BSD...
Emmanuel Delahaye
"C is a sharp tool"
There's a Windows way to do it also, but it requires you to install a *nix based OS...
Quzah.
Hope is the first step on the road to disappointment.
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
"Assumptions are the mother of all **** ups!"
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.Originally Posted by Kinasz
Emmanuel Delahaye
"C is a sharp tool"
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" ?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.
"Assumptions are the mother of all **** ups!"
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.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.Originally Posted by Kinasz
Emmanuel Delahaye
"C is a sharp tool"