• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

How to hide the typed characters

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
rasaraja
Asked:
rasaraja
  • 3
  • 2
  • 2
  • +2
1 Solution
 
garbouaCommented:
why don't you use pam?
0
 
ahoffmannCommented:
see ioctl()
0
 
rasarajaAuthor Commented:
Would you kindly be a bit more descriptive?What's pam ?
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
bryanhCommented:
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
 
rasarajaAuthor Commented:
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
 
bryanhCommented:
What library does the compiler (or whatever) complain about being undefined?  Could you post the exact error messages?
0
 
acarnaCommented:
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
 
rasarajaAuthor Commented:
Acarna,this is exactly what I was looking for.But it does not seem that getpass() truncates to 8 chars.
0
 
acarnaCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now