C Programming code for Password Cheak Strings – KLETech

Write a Modular C Programming Code for Password Cheak Strings | Sentence?

Condition: contains at least 8 characters in length, must contain one uppercase, one lowercase, one special character, and one digit.

CODE:

#include<stdio.h>
#include<string.h>
#define MAX 100
int check_password(char password[]);
main()
{
char password[MAX];
while(1)
{
printf("\nEnter the password:\n");
gets(password);
if(check_password(password))
{
printf("Password is valid:\n");
break;
}
else
{
printf("\nPassword must be of atleast 8 characters in length, with one upper-case, one lower-case, one digit and one special character\n");
}
}
}

int check_password(char password[])
{
int i;
int upper_flag = 0;
int lower_flag = 0;
int special_flag = 0;
int digit_flag = 0;
if(strlen(password)<8)
return 0;
else
{
while(password[i]!='\0')
{
if(password[i] >='A' && password[i]<='Z')
upper_flag = 1;
else if(password[i] >='a' && password[i]<='z')
lower_flag = 1;
else if(password[i] >='0' && password[i]<='9')
digit_flag = 1;
else
special_flag =1;
i++; //Next character
}//end while
if(upper_flag == 1 && lower_flag == 1 && digit_flag == 1
&& special_flag == 1)
return 1;
else
return 0;
}//end outer else
}

 

OUTPUT

Enter the password:
[email protected]

Password must be of atleast 8 characters in length, with one upper-case, one lower-case, one digit and one special character

Enter the password:
[email protected]

Password must be of atleast 8 characters in length, with one upper-case, one lower-case, one digit and one special character

Enter the password:
[email protected]

Password must be of atleast 8 characters in length, with one upper-case, one lower-case, one digit and one special character

Enter the password:
[email protected]
Password is valid:

Process returned 0 (0x0) execution time : 85.157 s
Press any key to continue.

 

Please find some more codes of 1D Arrays, 2D Arrays, Pointers on the below page:

Top 100+ C Programming codes – KLE Technological University

 

Leave a Comment