Advertisement
fahimkamal63

Password Checker

Dec 9th, 2019
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. //  Password Checker
  2. //  Date: 09.12.19
  3. #include<stdio.h>
  4. #include<conio.h>
  5. #include<string.h>
  6.  
  7. int main(){
  8.     //  Change these two as you like
  9.     //  You will have to enter them as input
  10.     //  when running the program.
  11.     char userName[] = "user";
  12.     char password[] = "password";
  13.  
  14.     int userNameLength = (sizeof(userName) / sizeof(char));
  15.     int passwordLength = (sizeof(password) / sizeof(char));
  16.  
  17.     char inputUserName[userNameLength];
  18.     char inputPassword[passwordLength];
  19.  
  20.     printf("Enter User Name: ");
  21.     scanf("%s", inputUserName);
  22.     printf("Enter password: ");
  23.     int i;
  24.  
  25.     //  When typing the password you will see '*'
  26.     //  Because of below for loop.
  27.     //  getch() function takes only one char as input
  28.     for(i = 0; i < passwordLength-1; i++){
  29.         inputPassword[i] = getch();
  30.         printf("*");
  31.     }
  32.     //  '\0' has to be added at the last of the char array
  33.     //  inorder to make the char array a string.
  34.     inputPassword[i] = '\0';
  35.  
  36.     //  Checking if the user inputs and the user name and the password is same or not.
  37.     if(!strcmp(userName, inputUserName) && !strcmp(password, inputPassword)){
  38.         printf("\n\nPassword Correct! \n\n");
  39.         printf("Welcome! %s \n\n", userName);
  40.     }
  41.     else{
  42.         printf("\n\nInvalid user name or password.\n");
  43.     }
  44. }
  45. //  Do a little bit of research on it.
  46. //  Still not clear then ask.
  47. //  Try not to memorize but to understand.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement