C Project – How to Read a Password in C with Source Code
Get Certified in C Programming and Take Your Skills to the Next Level
Program 1
#include<stdio.h>
#include<conio.h>
#define clrscr() system("cls")
int main()
{
static int i=0;
char ch1,ch2,ch3,ch4;
clrscr();
pin:printf("\nEnter a pin: ");
ch1=getch();
printf("*");
ch2=getch();
printf("*");
ch3=getch();
printf("*");
ch4=getch();
printf("*");
if(ch1=='1'&&ch2=='2'&&ch3=='3'&&ch4=='4')
printf("\nYou are valid user");
else
{
if(i==2)
{
printf("Contact to admin......");
exit(0);
}
else
{
i++;
printf("\nIncorrect pin...... enter again\n");
goto pin;
}
}
}Program 2
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define clrscr() system("cls")
int main()
{
int p=0,i=0;
char ch,pass[50],pass1[50];
clrscr();
printf("\nEnter a password: ");
while(1)
{
ch=getch();
printf("*");
if(ch==9)
continue;
if(ch==13)
break;
pass[p]=ch;
++p;
}
if(pass[0]=='m' && pass[1]=='o'&& pass[2]=='n' && pass[3]=='u')
printf("Valid user");
else
printf("In valid password.....");
}
If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google

