replylalit
asked on
password entry in console application
Dear all,
I am developing a console based application and it requires a password entry field. I want that password should not be printed in screen (rather some character should be displayed instead)
eg.
Enter password : *****
Please comment!
I am developing a console based application and it requires a password entry field. I want that password should not be printed in screen (rather some character should be displayed instead)
eg.
Enter password : *****
Please comment!
may be setattr() function
this works on windows... on linux u need slightly special stuff
#include<stdio.h>
#include<conio.h>
void main()
{
int a,i;
char c,buf[32];
printf(" input password.... ");
i=0;
while((c=getch())!='\r'){
printf("%c",'*');
buf[i++]=c;
}
buf[i]='\0';
printf("\nu entered password %s\n",buf);
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,i;
char c,buf[32];
printf(" input password.... ");
i=0;
while((c=getch())!='\r'){
printf("%c",'*');
buf[i++]=c;
}
buf[i]='\0';
printf("\nu entered password %s\n",buf);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Read the characters using getch () in a loop and keep storing them in an array, and keep displaying '*' for every character entered.
Mayank.
Mayank.
>> Read the characters using getch () in a loop and keep storing them in an array, and keep displaying '*' for every character entered.
That is EXACTLY what the previously posted code does. :-)
Exceter
That is EXACTLY what the previously posted code does. :-)
Exceter
>>>That is EXACTLY what the previously posted code does. :-)
and the prior to that one too :P
strange stats .. today most of the notifications that came to me..80 % were comment from Mayankeagle..
and many of them were similar like this one ... repeated ideas..
and the prior to that one too :P
strange stats .. today most of the notifications that came to me..80 % were comment from Mayankeagle..
and many of them were similar like this one ... repeated ideas..
>> today most of the notifications that came to me..80 % were comment from Mayankeagle..
>> and many of them were similar like this one ... repeated ideas..
I noticed that same phenomenon..
Exceter
>> and many of them were similar like this one ... repeated ideas..
I noticed that same phenomenon..
Exceter
try this :
void input() {
char c[8];
int index = 0;
while (1) {
c[index] = getch();
printf("*");
index++;
if (index == 8) {
c[index] = '\0';
break;
}
}
/* printf("%s\n", c); */
}
this should do the trick, i hope. anyway, it is just a sample that will accept input of 8 characters and exit the while loop.
void input() {
char c[8];
int index = 0;
while (1) {
c[index] = getch();
printf("*");
index++;
if (index == 8) {
c[index] = '\0';
break;
}
}
/* printf("%s\n", c); */
}
this should do the trick, i hope. anyway, it is just a sample that will accept input of 8 characters and exit the while loop.
oopps... sorry, didnt notice that it is the same...
oopps... sorry, didnt notice that it is the same...
How about rating it now?
Nothing has happened on this question in more than 8 months. It's time for cleanup!
My recommendation, which I will post in the Cleanup topic area, is to
accept answer by Exceter.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jmcg
EE Cleanup Volunteer
My recommendation, which I will post in the Cleanup topic area, is to
accept answer by Exceter.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jmcg
EE Cleanup Volunteer
or use getch() to get one by one character in a password string