Question #82844

write a program that prompts for the name and password of a user. The program displays "congratulations, you are logged in." if the user enters the correct password or "Wrong password.Try Again" for a wrong password on which it displays "Sorry, your account is locked, contact the system administrator" if all the three attempts are wrong. use C programming

Expert's answer

#include <stdio.h>
#include <stdlib.h>
#define USER "user"
#define PASSWORD "1234"
char login[16] = USER;
char password[16] = PASSWORD;
int Login()
{
    char loginFromInput[16];
    char passwordFromInput[16];
    int i;
    for (i=0; i<3; i++)
    {
        printf("Please type your username: \n");
        scanf("%s", &loginFromInput);
        printf("Please type your password: \n");
        scanf("%s", &passwordFromInput);
        if(CheckForPassword(loginFromInput, passwordFromInput))
        {
            printf("Login successful");
            return 1;
        }
        printf("Wrong password.Try Again \n");
    }
    printf("Sorry, your account is locked, contact the system administrator");
    return 0;
}
int CheckForPassword(char * loginInput, char * passwordInput)
{
    if (!strcmp(login, loginInput) && !strcmp(password, passwordInput))
        return 1;
    else
        return 0;
}
int main()
{
    Login();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS