Best Industrial Training in C,C++,PHP,Dot Net,Java in Jalandhar

Sunday, 22 March 2015

Login Program in C?

#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
   char userid[]="admin",password[]="123",p[15],u[15];
   int n=1,a,b;
   printf("\nEnter USER ID and PASSWORD below (You have only three chances to enter)");
   getch();
   while(n<=3)
   {
      clrscr();
      printf("\nUSER ID: ");
      scanf("%s",u);
      printf("\nPASSWORD: ");
      scanf("%s",p);
      a=strcmp(u,userid);
      b=strcmp(p,password);
      if(a==0&&b==0)
      {
         printf("\nYou have logged in successfully.");
         break;
      }
      else
      {
         printf("\nWrong PASSWORD and/or USER ID. Now you have % d more chance/s.",3-n);
      }
      getch();
      n++;
   }
   if(n==4)
      printf("\nYou can't log in.");
   getch();
}