Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to disable/enable displaying user input in console

Reply
Thread Tools

How to disable/enable displaying user input in console

 
 
kimso.zhao@gmail.com
Guest
Posts: n/a
 
      11-30-2005
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.

 
Reply With Quote
 
 
 
 
Thomas Tutone
Guest
Posts: n/a
 
      11-30-2005
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-lit...html#faq-15.18

Best regards,

Tom

 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      11-30-2005
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.

 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      11-30-2005
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.
 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      12-01-2005

<> wrote in message
news: oups.com...
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Ignore F1-F12 keys when user enters text input on console Deiva Rajasingam Ruby 3 07-29-2009 06:21 AM
Best way to get user input from the console window? Sean W Java 2 08-31-2006 03:41 PM
how to non-stop read the input character and without user press enter in console mode. penny336 C++ 4 01-15-2004 03:24 PM
How to wait for user console input OR (!!!) changing of a variable contents (threads used) Tobias Merler Java 0 08-25-2003 07:04 PM



Advertisments