Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

hide console input

Posted on 2003-11-03
5
Medium Priority
?
961 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 120 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 90 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

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 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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

715 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