Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Password Checker
- // Date: 09.12.19
- #include<stdio.h>
- #include<conio.h>
- #include<string.h>
- int main(){
- // Change these two as you like
- // You will have to enter them as input
- // when running the program.
- char userName[] = "user";
- char password[] = "password";
- int userNameLength = (sizeof(userName) / sizeof(char));
- int passwordLength = (sizeof(password) / sizeof(char));
- char inputUserName[userNameLength];
- char inputPassword[passwordLength];
- printf("Enter User Name: ");
- scanf("%s", inputUserName);
- printf("Enter password: ");
- int i;
- // When typing the password you will see '*'
- // Because of below for loop.
- // getch() function takes only one char as input
- for(i = 0; i < passwordLength-1; i++){
- inputPassword[i] = getch();
- printf("*");
- }
- // '\0' has to be added at the last of the char array
- // inorder to make the char array a string.
- inputPassword[i] = '\0';
- // Checking if the user inputs and the user name and the password is same or not.
- if(!strcmp(userName, inputUserName) && !strcmp(password, inputPassword)){
- printf("\n\nPassword Correct! \n\n");
- printf("Welcome! %s \n\n", userName);
- }
- else{
- printf("\n\nInvalid user name or password.\n");
- }
- }
- // Do a little bit of research on it.
- // Still not clear then ask.
- // Try not to memorize but to understand.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement