Solved

hide console input

Posted on 2003-11-03
5
953 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
shell script working with --daemon 18 93
linux $PWD 2 592
Help with a backup script in Linux 4 75
Linux: disable vim auto-comment 7 91
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…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

930 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now