C Program to Illustrate how User Authentication is Done

This is a C program to illustrate user authentication.

Problem Description

This C program asks for the user name & password and displays the same to illustrate user authentication.

Problem Solution

1. Take the user name & password as input.
2. Print the each character of password as * while receiving it.
3. Now print the original password and exit.

Program/Source Code

Here is source code of the C program to illustrate user authentication. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C program is to illustrate how user authentication is done.
  3.  * Program asks for the user name and password and displays
  4.  * the password as '*' character
  5.  */
  6. #include <stdio.h>
  8. void main()
  9. {
  10. 	char password[10], username[10], ch;
  11. 	int i;
  13. 	printf("Enter User name: ");
  14. 	gets(username);
  15. 	printf("Enter the password < any 8 characters>: ");
  16. 	for (i = 0; i < 8; i++)
  17. 	{
  18.             ch = getchar();
  19.             password[i] = ch;
  20.             ch = '*' ;
  21.             printf("%c", ch);
  22. 	}
  23.         password[i] = '\0';
  24. 	/*  Original password can be printed, if needed */
  25. 	printf("\n Your password is :");
  26. 	for (i = 0; i < 8; i++)
  27. 	{
  28.             printf("%c", password[i]);
  29. 	}
  30. }
Program Explanation

1. Take the username as input and store it in the array username[].
2. Using for loop take the each character of password as input and store it in the array password[] and consecutively print it as ‘*’.
3. Print the array password[] as output and exit.

Runtime Test Cases
Enter User name: rajaraman
Enter the password <any 8 characters>: shashi12
Your password is :shashi12

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Here’s the list of Best Books in C Programming, Data-Structures and Algorithms

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
If you wish to look at other example programs on Simple C Programs, go to Simple C Programs. If you wish to look at programming examples on all topics, go to C Programming Examples.

If you find any mistake above, kindly email to [email protected]

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.