Advertisement
Guest User

Untitled

a guest
Jan 14th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. //Hisham Salah
  5.  
  6. int userAndpassChecker(char U[], char P[]) {
  7.  
  8.     char usern[20] = "admin123";
  9.     char passw[20] = "admin123admin";
  10.     int c = 0;
  11.  
  12.     for (int j = 0; U[j]!='$' ;j++) {
  13.  
  14.         if (U[j] != usern[j])
  15.             return 0;
  16.         else
  17.             c++;
  18.     }
  19.  
  20.     if (c != 8)
  21.         return 0;
  22.     else
  23.         c = 0;
  24.  
  25.     for (int h = 0; P[h]!='$';h++) {
  26.  
  27.         if (P[h] != passw[h])
  28.             return 0;
  29.         else
  30.             c++;
  31.     }
  32.  
  33.     if (c != 13)
  34.         return 0;
  35.  
  36.     return 1;
  37. }
  38. int main() {
  39.  
  40.  
  41.     char user[100] = { 0 };
  42.     char pass[100] = { 0 };
  43.  
  44.  
  45.  
  46.     printf("\n\nTo access the administrator page , please enter your username and passowrd\n\n");
  47.  
  48.     printf("\nEnter the username..... For Example Name$ (It should end with $)\n");
  49.  
  50.     for (int i = 0; user[i - 1] != '$';i++)
  51.         scanf_s("%c", &user[i]);
  52.  
  53.     printf("\nEnter the password..... For Example Pass123$ (It should end with $)\n");
  54.  
  55.     for (int j = 0; pass[j - 1] != '$';j++)
  56.         scanf_s("%c", &pass[j]);
  57.  
  58.     while (userAndpassChecker(user, pass) != 1){
  59.             printf("\nWrong username or passowrd ... Please re-enter username and password\n");
  60.  
  61.             printf("\nPlease enter the username:");
  62.  
  63.             for (int i = 0; user[i - 1] != '$';i++)
  64.                 scanf_s("%c", &user[i]);
  65.  
  66.             printf("\nPlease enter the password:");
  67.  
  68.             for (int j = 0; pass[j - 1] != '$';j++)
  69.                 scanf_s("%c", &pass[j]);
  70.         }
  71.        
  72.  
  73.    
  74.     printf("\nYou have access to the administrator page\n");
  75.  
  76.  
  77.  
  78.  
  79.     system("pause");
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement