hi friends,
how to not display the user input password in C,It is similar to the oracle SQL Plus.This is also for safety reasons.
thanks.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jul 28, 2012, 12:09 PM
So to stop them printing an asterisk, we need to trap these two characters and the next character as well.
I've altered the program to deal with that but, if you're using an OS other than Windows or a non-English keyboard, then I can't promise it will work as the keyboard mappings may be different.
I've also replaced the isalnum() library function with the corresponding bool expression as the former seems to have some issues when passed non-printing characters:
#include "stdio.h"
#include "conio.h"
#include "ctype.h"
int main()
{
char password[15]; /* max length 14 characters say */
int i;
for(i = 0; i < 15; i++) password[i] = '\0';
int index = 0;
int controlKey = 0;
printf("Enter password : ");
while(index < 14)
{
char ch = getch();
if (controlKey == 1)
{
controlKey = 0;
}
else if(ch == 13) /* enter key */
{
break;
}
else if (ch == 8) /* backspace key */
{
if (index > 0)
{
putchar(8);
putchar('\0');
putchar(8);
index--;
password[index] = '\0';
}
}
else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'))
{
putchar('*');
password[index] = ch;
index++;
}
else if (ch == 0 || ch == -32 )
{
controlKey = 1;
}
}
printf("\nYour password is %s\n\n", password);
return 0;
}
Ken HPosted Jul 28, 2012, 2:07 AM
thanks
Ken HPosted Jul 26, 2012, 9:47 PM
VulpesPosted Jul 26, 2012, 1:26 PM
It also supports the backspace key and (of course) the enter key:
Ken HPosted Jul 26, 2012, 4:44 AM
I want to achieve the same effect with the oracle SQL Plus,is DOS-based.
thanks
Atul KumarPosted Jul 26, 2012, 4:38 AM