c programming

Password Program In C Programming


If you had made a project in c programming and want to add user name and password protection on it. Then you are lucky that you find this blog. The password is the most common way to protect any thing from another user or to limit users to use this program.

In c programming, you can easily add password program in any other c program. In this tutorial, I will provide you password program in c programming. So let’s start.

Note: After password program, you must add loading program to make you project more attractive. 

Password Program In C Programming:

The simple password program in c programming will be like this:

#include <stdio.h>
#include <string.h>
int main(void)
    const char password[15] = “allow”;
    const char username[15]=”farhan”;
    char pass[15],user[15];
    int x,i;
    int log = 0;
    printf(“Enter Username: “);
    printf(“Enter your password: “);
    scanf(“%s”, &pass);
    if(strcmp(pass, password) != 0 && strcmp(user, username) !=0)
log = 1;
for(x = 0; x < strlen(pass); x++)
for(i=0; i<strlen(user);i++)
  { log=1;}
   if(pass[x] != password[x])
log = 1;
    if(log == 0)
printf(“nSuccessful login…n”);
printf(“nInvalid password! or Usernamen”);


    return 0;

Output Of Password Program:


Feature Of Password Program in C Programming:

The main features of adding or learning password program are:
  • For loops are used.
  • If and else conditions are used.
  • String functions are used.

String Functions:

  1. strcmp is a string function used to compare two strings.
  2. strlen is another string function used to calculate the length of a string.


I have provided you password program in c programming for your help. If you are feeling any difficulty in this program feel free to comment below.

Farhan khursheed

Farhan Khursheed is a passionate blogger from Karachi, Pakistan. He loves to write about SEO, Internet tips, and tricks, and earn online. He also loves programming.

Leave a Reply

Your email address will not be published. Required fields are marked *