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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jul 28, 2012, 8:09 AM EDT
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;
}
Atul KumarRank #1,527 · 1K reputationPosted Jul 26, 2012, 12:38 AM EDT
Ken HRank #2,315 · 610 reputationPosted Jul 26, 2012, 12:44 AM EDT
I want to achieve the same effect with the oracle SQL Plus,is DOS-based.
thanks
VulpesRank #55 · 29.2K reputationPosted Jul 26, 2012, 9:26 AM EDT
It also supports the backspace key and (of course) the enter key:
Ken HRank #2,315 · 610 reputationPosted Jul 26, 2012, 5:47 PM EDT
Ken HRank #2,315 · 610 reputationPosted Jul 27, 2012, 10:07 PM EDT
thanks