Solved

How to hide the typed characters

Posted on 2001-09-03
9
190 Views
Last Modified: 2013-12-03
I want to accept the password,so don't want to display the characters.How do I hide this ,I am using C ang Gcc to compile.
Using getch() gives a peculiar error.Says two other library functions are undefined.
Help.
0
Comment
Question by:rasaraja
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 5

Expert Comment

by:garboua
ID: 6453629
why don't you use pam?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6456131
see ioctl()
0
 

Author Comment

by:rasaraja
ID: 6459249
Would you kindly be a bit more descriptive?What's pam ?
0
 
LVL 5

Expert Comment

by:bryanh
ID: 6468955
I assume you're reading the password from a regular tty (terminal; virtual console; X pseudo-tty; whatever).  What causes what you type to display on the terminal is the tty line discipline (basically, a device driver) in the kernel.  You can change this default setting with a command 'stty -echo" (and view the current settings with 'stty -a').  Do a 'man stty' and play around with it.

Stty turns echoing on and off by issuing a TCSETATTR ioctl, via the tcsetattr() library function.  Man tcsetattr (or better, read the GNU C library user's guide) for details.  Your program can turn echoing off with a tcsetattr(), read the password, then turn echoing back on.

As for why getch() doesn't work for you, that's another question and you need to provide more details.  It works for me.

I know little about pam -- I have found it only to be a pain in the butt.  However, it provides library functions that handle the turning off of echoing and many other things.  If it's not too complicated for what you're doing, it might be the right way to go and garboua can give you more information.




0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:rasaraja
ID: 6469299
HI bryanh,

It would be great if u can tell me how I can use getch.I am ready tp provide all the details you require.
0
 
LVL 5

Expert Comment

by:bryanh
ID: 6471233
What library does the compiler (or whatever) complain about being undefined?  Could you post the exact error messages?
0
 

Accepted Solution

by:
acarna earned 50 total points
ID: 6478212
Hi!
Also you could use the getpass() function:

#include <stdlib.h>

char *getpass(const char *prompt);


Note that "getpass" truncates the typed password to at most eight characters.


Regards.

Ariel.
0
 

Author Comment

by:rasaraja
ID: 6481258
Acarna,this is exactly what I was looking for.But it does not seem that getpass() truncates to 8 chars.
0
 

Expert Comment

by:acarna
ID: 6481440
Oh, yes! If you are using a modern Unix maybe the function don't truncate the string but the primitive and old getpass(), you can be sure truncate the data.
Have this in mind in matters as portability.

Regards.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
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.

760 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

22 Experts available now in Live!

Get 1:1 Help Now