C Program to implement the authentication system using a password

For a better understanding, we always recommend you to learn the basic topics of C programming listed below:

How to do an authentication security system using the password in C?

By using this c program, we can easily understand how to read a password from the user. Authentication is crucial in the digital world as all our data is vulnerable to hacking or being stolen. An authentication system is defined as we restrict the users to enter somewhere without credentials like Facebook or Twitter, or google mail. We need to implement a username and password system for secured authentication.

How is security authentication with the password implemented in C?

Here in this c program, we are just getting the user input as username and password; we need to put 'stars' for a password to maintain security. Finally, we need to display the user input password, for that we accept the username using gets. For password, we open a loop and use getch to get each letter user enters and adds the letters into the password array. Then prints 'stars' for password. Finally, we need to print the password in this c program. We use only three simple steps in this c program to implement the security system. They are:

1. Receive the username and password as input
2. Print every character of the password as *
3. Print the original password and then exit

The Algorithm and Source code to implement the Authentication Security System using a Password is:


STEP 1: Include the Header files to use the built-in functions in the C program.

STEP 2: Declare two Arrays, pasword[10], and usrname[10] of Data type character.

STEP 3: Read the Username from the user and store it in the variable usrname using 'gets()'

STEP 4: Read the Password from the user and store it in the variable paswrord and display the Password as ****

STEP 5: Set the last element of the Array as a NULL character.

STEP 6: Using a for loop with the condition 'i<8', Display each character from the Array password[i].

C Source Code

                                          #include <stdio.h>
void main()
 char password[10], username[10], ch;
 int i;
 printf("Enter User name: ");
 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]);


Enter User name: mona

Enter the password : ********
Your password is : stem123