I would like the input on the scanf
to show as asterisks opposed to the actual letters.
For example, when the program asks for a password, I would like it to show "******" instead of "PRG255".
Please let me know what you think and if it is possible with the current format of the code. This way, the password can stay safe if someone is looking at the user input the password.
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int stop = 0, length, i, key=55;
char decider, data[50], password[]="PRG255", passwordCheck[7];
while (stop != 1)
{
decider = NULL;
printf("\n(E)nter and encrypt a message \n(V)iew encrypted message\n(D)ecrypt and view message (password protected)\n(Q)uit\n\n");
scanf(" %c", &decider);
switch (decider)
{
case 'e':
case 'E':
flushall();
printf("\nEnter data to encrypt: ");
scanf("%s", data);
length = strlen(data);
for (i = 0; i < length; i++)
{
data[i] = data[i] ^ key;
}
break;
case 'v':
case 'V':
printf("\n%s\n", data);
break;
case 'd':
case 'D':
for(i = 0; i < 3; i++)
{
printf("please enter password(three attempts)\n");
scanf("%s", passwordCheck);
if (strcmp(password, passwordCheck) == 0)
{
for (i = 0; i < length; i++)
{
data[i] = data[i] ^ key;
}
printf("\n%s\n\n", data);
}
}
if (strcmp(password, passwordCheck) != 0)
{
printf("invalid password enetered three times! program will terminate now!\n\n");
return 0;
}
break;
case 'q':
case 'Q':
return 0;
break;
default:
printf("An invalid option was selected!\n\n");
}
}
}