Program in C that accepts username and password and performs login function
Write a program in C that perform login operation. The program will accept username and password as a string from the user. The valid username should be “user” and the valid password should be “default”.
If either of the username or password is incorrect then it should display the appropriate message. If username and password entered is correct, then it should display the message “User successfully logged in…”.
Here is the C program:
#include<stdio.h> #include<conio.h> #include<string.h> void main() { char *username; char *password; clrscr(); printf("Enter the username: "); gets(username); printf("\nEnter the password: "); gets(password); if(strcmp(username, "user") == 0){ //username verification sucessful //next step is to verify the password if(strcmp(password, "default") == 0){ //password verification also successful printf("\nUser successfully logged in..."); }else{ //invalid password. Report it printf("\nPassword entered is invalid"); } }else{ //invalid username. Report it printf("\nUsername entered is invalid"); } getch(); }
Output:
Enter the username: user Enter the password: default User successfully logged in...
2 Responses
[…] Login operation using C – Accepts username and password … […]
[…] Login operation using C – Accepts username and password … […]