This is a C program to illustrate user authentication.
This C program asks for the user name & password and displays the same to illustrate user authentication.
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.
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.
/*
* C program is to illustrate how user authentication is done.
* Program asks for the user name and password and displays
* the password as '*' character
*/
#include <stdio.h>
void main()
{
char password[10], username[10], ch;
int i;
printf("Enter User name: ");
gets(username);
printf("Enter the password < any 8 characters>: ");
for (i = 0; i < 8; i++)
{
ch = getchar();
password[i] = ch;
ch = '*' ;
printf("%c", ch);
}
password[i] = '\0';
/* Original password can be printed, if needed */
printf("\n Your password is :");
for (i = 0; i < 8; i++)
{
printf("%c", password[i]);
}
}
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.
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
- Watch Advanced C Programming Videos
- Practice Computer Science MCQs
- Apply for C Internship
- Check Computer Science Books
- Apply for Computer Science Internship