Solved

hide console input

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

11 Experts available now in Live!

Get 1:1 Help Now