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.

advertisement
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>
  7.  
  8. void main()
  9. {
  10. 	char password[10], username[10], ch;
  11. 	int i;
  12.  
  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.

advertisement
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 Reference Books in C Programming, Data-Structures and Algorithms

advertisement
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.

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn