How to disable/enable displaying user input in console

Discussion in 'C++' started by kimso.zhao@gmail.com, Nov 30, 2005.

  1. Guest

    Hi All,

    I need a function that when user types a password in the console, the
    password should be invisible (e.g. display nothing or display "*"
    instead). Just as you can see when you login a machine.

    How to implement this? Thanks!
    Note: user is typing passord in the console.
     
    , Nov 30, 2005
    #1
    1. Advertising

  2. Re: How to disable/enable displaying user input in console

    wrote:
    > I need a function that when user types a password in the console, the
    > password should be invisible (e.g. display nothing or display "*"
    > instead). Just as you can see when you login a machine.
    >
    > How to implement this? Thanks!
    > Note: user is typing passord in the console.


    Your question is answered in the FAQ:

    http://www.parashift.com/c -faq-lite/input-output.html#faq-15.18

    Best regards,

    Tom
     
    Thomas Tutone, Nov 30, 2005
    #2
    1. Advertising

  3. Rolf Magnus Guest

    wrote:

    > Hi All,
    >
    > I need a function that when user types a password in the console, the
    > password should be invisible (e.g. display nothing or display "*"
    > instead). Just as you can see when you login a machine.
    >
    > How to implement this? Thanks!
    > Note: user is typing passord in the console.


    There is no standard C++ way to do that, because the C++ doesn't define a
    console, but rather only an input stream (that may be connected to a
    keyboard or not) and some output streams (that may be connected to a
    display or not). You will need some platform-specific functions.
    Maybe the (n)curses library can help you.
     
    Rolf Magnus, Nov 30, 2005
    #3
  4. Ron Natalie Guest

    wrote:
    > Hi All,
    >
    > I need a function that when user types a password in the console, the
    > password should be invisible (e.g. display nothing or display "*"
    > instead). Just as you can see when you login a machine.
    >
    > How to implement this? Thanks!
    > Note: user is typing passord in the console.
    >

    What consoles do is system dependent. You need to ask
    in a group for your operating system (and possibly
    windowing system) ... windows, unix, etc...

    C++ doesn't address this.
     
    Ron Natalie, Nov 30, 2005
    #4
  5. Jim Langston Guest

    <> wrote in message
    news:...
    > Hi All,
    >
    > I need a function that when user types a password in the console, the
    > password should be invisible (e.g. display nothing or display "*"
    > instead). Just as you can see when you login a machine.
    >
    > How to implement this? Thanks!
    > Note: user is typing passord in the console.


    Use whatever OS specific call you have to read a key from the keyboard. It
    is different for each OS. Then get a keypress, and print "*" to the screen.

    char Input;
    std::string Password;
    while ( Input = FunctionToGetKeypress() != 13 ) // 13 is usually enter
    {
    Password += Input;
    std::cout << "*";
    cout.flush(); // May or may not be needed
    }
    std::cout << std::endl;

    for Windows it's getch()
    Not sure for linux.
    check for your OS what function it is to get a single key press.
     
    Jim Langston, Dec 1, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. buran
    Replies:
    2
    Views:
    1,814
    buran
    Sep 26, 2003
  2. Patrick
    Replies:
    1
    Views:
    660
  3. =?Utf-8?B?VmVhcg==?=

    Can you disable / enable user accounts with aspnetdb?

    =?Utf-8?B?VmVhcg==?=, Apr 24, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    479
    =?Utf-8?B?VmVhcg==?=
    Apr 24, 2006
  4. Vear

    Disable and Enable user Account

    Vear, Apr 23, 2006, in forum: ASP .Net Security
    Replies:
    0
    Views:
    120
  5. buran
    Replies:
    2
    Views:
    182
    buran
    Sep 26, 2003
Loading...

Share This Page