stop input being echoed

This is a discussion on stop input being echoed within the C Programming forums, part of the General Programming Boards category; For password input, Is there a way in ansi c to stop input being echoed? I would ideally like to ...

  1. #1
    zsaniK Kinasz's Avatar
    Join Date
    Jan 2003
    Posts
    222

    stop input being echoed

    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!"

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.

  3. #3
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    like quzah said, there's no portable way. On *nix with curses/ncurses you can use noecho(); to disable charater echo at input.

  4. #4
    Helper
    Join Date
    Jun 2004
    Posts
    255
    Quote Originally Posted by Kinasz
    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.
    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).
    Last edited by Emmanuel Delaha; 07-25-2004 at 05:35 AM. Reason: typo
    Emmanuel Delahaye

    "C is a sharp tool"

  5. #5
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    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.

  6. #6
    Helper
    Join Date
    Jun 2004
    Posts
    255
    Quote Originally Posted by viaxd
    Emmanuel, from my man page on getpass():
    Code:
     This function is obsolete. Do not use it.
    Yes. It sounds that the correct functions belong to

    fgetpwent()
    getpwnam()
    getpwuid()
    getpw()
    putpwent()
    passwd()

    But i'm not sure there are POSIX.... More UNIX/BSD...
    Emmanuel Delahaye

    "C is a sharp tool"

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.

  8. #8
    zsaniK Kinasz's Avatar
    Join Date
    Jan 2003
    Posts
    222
    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!"

  9. #9
    Helper
    Join Date
    Jun 2004
    Posts
    255
    Quote Originally Posted by Kinasz
    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.
    Emmanuel Delahaye

    "C is a sharp tool"

  10. #10
    zsaniK Kinasz's Avatar
    Join Date
    Jan 2003
    Posts
    222
    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.
    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" ?
    "Assumptions are the mother of all **** ups!"

  11. #11
    Compulsive Liar Robc's Avatar
    Join Date
    Jul 2004
    Posts
    149
    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" ?
    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.

  12. #12
    Helper
    Join Date
    Jun 2004
    Posts
    255
    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" ?
    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.
    Emmanuel Delahaye

    "C is a sharp tool"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input class project (again)
    By Elysia in forum C++ Programming
    Replies: 41
    Last Post: 02-13-2009, 09:52 AM
  2. Input statement problem
    By une in forum C Programming
    Replies: 3
    Last Post: 05-29-2007, 11:16 PM
  3. Determining if input is int, double, or char
    By Lucid003 in forum C++ Programming
    Replies: 4
    Last Post: 11-16-2005, 03:16 PM
  4. EOF messing up my input stream?
    By Decrypt in forum C++ Programming
    Replies: 4
    Last Post: 09-30-2005, 03:00 PM
  5. Simple Console Input for Beginners
    By jlou in forum C++ Programming
    Replies: 0
    Last Post: 06-21-2005, 01:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21