Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hiding a password typed in an Xterm using C

Status
Not open for further replies.

Jabrant

Programmer
Sep 6, 2001
2
US
I am currently writing a C program in the UNIX environment that asks the user to enter a password. I am looking for a way to have their input not be displayed on the screen while they are typing. I noticed here at work when logging onto a server via an Xterm when asked for my password -- nothing happens on the screen. Does anyone know how to do this or other easy ways to hide the password from being displayed. Thanks so much.
 
Never tried it but throw this in ad see what happens

printf("\r ");

i think this will bring you back to the beginning of the line and replace what is written with a space.

Matt
 
int i = 0;
char* pwd = NULL;
while(x != 13)
{
x = getch();
putc('*');

if(x == 0)
{
getch();
break;
}else if(x == '\b')
{
if(x)x--;
contine;
}else ...of other key
pwd = realloc(pwd, i+1);
pwd = x;
i++;
}
i++;
pwd = 0;

Ion Filipski
1c.bmp


filipski@excite.com
 
The getch() function doesn't display the character entered, that is the way the UNIX passw are not show.
[red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
 
remember to use getch() and not getche(), the 'e' in the latter case will echo the character typed.

Also, you could also display '*' as the case in windows when it comes to echoing password.

Sriks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top