To find strength of the password

To find strength of the password

Question:

Find the strength of the password string based on the conditions.

Conditions:

  • Length of the password is always greater than 8.
  • It contains at least one numeral.
  • It contains at least one symbol.
  • It contains at least one uppercase alphabet.

Algorithm:

  1. Get the password from the user.
  2. Then check the length of the password is >8.
  3. Check for any numerals, symbols, and uppercase alphabets.
  4. Use marker variables for checking the at least one value(numerals, symbols, uppercase) is present in the string.
  5. Print the strength of the password.

Program:

#include<stdio.h>
void main()
{
	//n->length of the string
	//cnt->to count the strength
	//f->as a marker for alphabets
	//c->as a marker for numerals
	//d->as a marker for symbols
	//e->as a marker for upper case
	char a[20],i,n,cnt=0,c=0,d=0,e=0,f=0;
	clrscr();
	printf("enter the password:");
	gets(a);
	n=strlen(a);
	if(n>7)                                        //enters only when length greater then 7
	{
		for(i=0;i<n;i++) { if(a[i]>='a'&&a[i]<='z'&&f==0) //checks for alphabets { cnt++; f=1; } else if(a[i]>='A'&&a[i]<='Z'&&f==0) //checks for alphabets { cnt++; f=1; } if(a[i]>='0'&&a[i]<='9'&&c==0) //checks for numerals { cnt++; c=1; } if(a[i]>='!'&&a[i]<='/'&&d==0) //checks for symbols { cnt++; d=1; } else if(a[i]>=':'&&a[i]<='@'&&d==0) { cnt++; d=1; } else if(a[i]>='{'&&a[i]>='~'&&d==0)
			{
				cnt++;
				d=1;
			}
			if(a[i]>='A'&&a[i]<='Z'&&e==0)          //checks for upper case 
			{
				cnt++;
				e=1;
			}
		}
	}
	switch(cnt)                                     //prints the strength of password
	{
		case 1: printf("weak");
			break;
		case 2: printf("Medium");
			break;
		case 3: printf("Good");
			break;
		case 4: printf("Strong");
			break;
		default:printf("Not valid");
	}
	getch();
}

You might also like:

>Program to print the mismatched characters

Vignesh

A Computer Science graduate who likes to make things simpler. When he’s not working, you can find him surfing the web, learning facts, tricks and life hacks. He also enjoys movies in his leisure time.