C Program to implement the authentication system using a password


February 15, 2022, Learn eTutorial
3083

What is an authentication security system?

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

How is security authentication with password implemented in C?

Here in this C program, we are just getting the user input as username and password; we need to hide the password with stars 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 print 'stars' for the password. Finally, we need to print the password. 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:

ALGORITHM

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


To implement the authentication system in C programming we need to refer these below topics, please refer these topics for a better understanding

C Source Code

                                          #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]);
 }
}
                                      

OUTPUT

Enter User name: mona

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