Advertisement
Guest User

Untitled

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