Advertisement
Md_Touhid

Password

Jan 21st, 2016
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. char pass[10];
  5. char saved_pass[10];
  6. int pass_length=8, chance=3, i, j, k, flag=0;
  7.  
  8. int main(void)
  9. {
  10.     int counter = chance-1;
  11.  
  12.     printf("You can save a password made of 3 to %d characters.", pass_length);
  13.     printf("\n\nChoose your password to save : ");
  14.     gets(saved_pass);
  15.  
  16.     if(strlen(saved_pass)>2 && strlen(saved_pass)<=pass_length)
  17.     {
  18.         printf("\n\nSuccessfully saved...");
  19.  
  20.         for(j=1; j<=chance; j++)
  21.         {
  22.  
  23.             printf("\n\nPlease enter your password : ");
  24.             int len = strlen(saved_pass);
  25.             for(i=0; i<len; i++)
  26.             {
  27.                 pass[i] = getch();
  28.                 printf("*");
  29.             }
  30.  
  31.             for(i=(strlen(saved_pass)-1), k=(strlen(pass)-1); i>=0; i--, k--)
  32.             {
  33.                 if(pass[k]==saved_pass[i])
  34.                 {
  35.                     flag = 1;
  36.                 }
  37.                 else
  38.                 {
  39.                     flag = 0;
  40.                     break;
  41.                 }
  42.             }
  43.  
  44.             if(flag==0)
  45.             {
  46.                 printf("\n\nWrong password!");
  47.                 printf("\n%d times remaining", counter);
  48.                 counter--;
  49.  
  50.             }
  51.             else if(flag==1) break;
  52.         }
  53.  
  54.         if(flag == 1) printf("\n\nLog on successful...\n\n");
  55.         else if(flag == 0) printf("\n\nAccess denied!\n\n");
  56.     }
  57.  
  58.     else  printf("\n\nInvalid password to save!\n\n");
  59.  
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement