Solved

hide console input

Posted on 2003-11-03
5
960 Views
Last Modified: 2009-12-16
Using C++, how to display a prompt for a password, ie a cin that will hide the text that the user types in?
0
Comment
Question by:fyuber
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9670022
Hi fyuber,

set noecho and use getch()
man getch() for more info

Cheers!
Sunny:o)
0
 
LVL 1

Author Comment

by:fyuber
ID: 9675751
Sorry, Im rather new to this. How to set noecho?
0
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 40 total points
ID: 9675834
Have you tried calling getpass() instead?

NAME
     getpass - get a password

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #include <pwd.h>
     #include <unistd.h>

     char *
     getpass(const char *prompt);

DESCRIPTION
     The getpass() function displays a prompt to, and reads in a password
     from, /dev/tty.  If this file is not accessible, getpass() displays the
     prompt on the standard error output and reads from the standard input.

     The password may be up to _PASSWORD_LEN (currently 128) characters in
     length.  Any additional characters and the terminating newline character
     are discarded.

     The getpass() function turns off character echoing while reading the
     password.

RETURN VALUES
     The getpass() function returns a pointer to the null terminated password.

0
 
LVL 1

Author Comment

by:fyuber
ID: 9677153
thanks, it works but i still want to know how to use sunny's method. guess I should increase points but I'll have to wait for them to accumulate.
0
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 30 total points
ID: 9677215
here are two more methods:

1. system ( "stty echo" );
    system ( "stty -echo" );  //look into man page before using this

2. using ncurses
    #include <curses.h>
     int noecho(void);
     man curs_inopts
0

Featured Post

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question