Wednesday, 12 September 2012

Program to Check the entered password is correct or not and if you enter the password it must be hidden by '*' character


main()
{
 char pw[25],un[25],pass[25];
 int i;
 printf("Enter Username :- ");
 scanf("%s",un);
 printf("Enter password ( max 25 characters) :- ");
 i=0;
 while(1)
 {
  pw[i]=getch();
  if(pw[i]==' ' || pw[i] == '\r')
  {
   pw[i]='\0';
   pass[i]='\0';
   break;
  }
  else
  {
   pass[i]=pw[i];
   printf("*");
  }
  i++;
 }
 printf("\n");
 if(strcmp(un,"Amit")==0 && strcmp(pass,"najnartima"==0))
  printf("Welcome! Mr. Amit ");
 else if(strcmp(pass,"najnartima")==0)
  printf("Welcome! Mr./Mrs./Miss. %s ! you know the password.",un);
 else
  printf("Sorry! Invalid password.");
 getch();
}

Output:-

No comments:

Post a Comment