Password Protection program with C language

Published October 01, 2021


This is a c program which will let you add Password Verification in any program of your choice of C or C++. You just have to add this peice of code to your code and you can use this feature as we have used in other programs.
To run this program you have to put the correct password which is "codewithc" .

 

Feature

  1. This program will let you add password before opening the real program
  2. Your program is as safe as your any other social media account
  3. You will not have to worry about your executable file to get in wrong hands
  4. Program will only rum if you type correct password

 

Output

Password is : codewithc

 

Example code

#include<windows.h>
#include<stdio.h>
#include<conio.h>
#include <stdlib.h>
#include<string.h>
#include<ctype.h>
#include<dos.h>
#include<time.h>


void Password();
void delay();


int main()
{
Password();
getch();
return 0;
}

void Password(void)
{

char password[10]={"codewithc"};
system("cls");
char d[26]="  Encrypted Program";
char ch,pass[10];
int i=0,j;
for(j=0;j<20;j++)
{
Sleep(50);
printf("*");
}
for(j=1;j<20;j++)
{
Sleep(50);
printf("%c", d[j]);
}
for(j=0;j<20;j++)
{
Sleep(50);
printf("*");
}

printf("\n\nEnter Password:");

while(ch!=13)
{
ch=getch();

if(ch!=13 && ch!=8){
putch('*');
pass[i] = ch;
i++;
}
}
pass[i] = '\0';
if(strcmp(pass,password)==0)
{
printf("\nverifying...");
for (i=0; i < 1; i++)
{
 delay(3);
printf("\n\nPassword matched :)");
}
for(i=0;i<1;i++)
{
 delay(2);
printf("\nPress any key to continue...");
}
getch();
}
else
{
printf("\nverifying...");
for(i=0; i<1;i++)
{
 delay(3);
printf("\n\n[!]Password didn't match :(");
}
for(i=0;i<1;i++)
{
 delay(2);
printf("\nPress any key to try again...");
}
getch();
Password();
}
}


void delay(int number_of_seconds)
{
    // Converting time into milli_seconds
    int milli_seconds = 1000 * number_of_seconds;

    // Stroing start time
    clock_t start_time = clock();

    // looping till required time is not acheived
    while (clock() < start_time + milli_seconds)
        ;
}

 

Output:

C program to password protection

 

How to make password protection with c program

 

 

C program for beginner - Password protection

 

C programs for beginners password protection

 

Conclusion: When we write projects with c programming there is a requirement to protect the password, here we learned how to make password protection

 

 

Download Source code

 

More Beginner Projects

Employee Management System with CPP

Python Library Management System

C Library Management System - LMS Project with C

Java Library Management System Source code

Calendar application with C Language

Contact Management System with C

Bank Management System with C


Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

60 Views

Subscribe For Daily Updates

Flutter Questions
Android Questions