Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design and implement the simulation of a finite automaton to determine whether a

ID: 3606955 • Letter: D

Question

Design and implement the simulation of a finite automaton to determine whether a password is valid or not.A valid password is defined as a string of at least 8 characters, and at most 10 .Two of these characters must be upper case letters,two of these characters must be digits,one of the characters must be a special character(@,%,#,$),one character must be a lower case lettter and the rest of the characters can be any combination of ascii characters

C or C++

Program must ask a user to type a password.The password is the input string to be accepted or rejected by the automaton.Your program must display the states the automaton moves to when reading each input symbol from the input spring.Do not use nested if’s for the simulation

Explanation / Answer

/******************************************************************************
Design and implement the c program to determine whether a password is valid or not.
A valid password is defined as a string of at least 8 characters, and at most 10 .
Two of these characters must be upper case letters,two of these characters must be digits,
one of the characters must be a special character(@,%,#,$),one character must be a lower case lettter
and the rest of the characters can be any combination of ascii characters
*******************************************************************************/

#include<stdio.h>
#include<stdlib.h>
void check(char a[]);//declare one function for validating password with array of characters
main()
{
char a[50];//creating one string with 50 size
printf("Enter your password that should satisfy the following criteria");//all 1 to 5 printf funnction for showing hint to user
printf(" 1. password length should be in 8 to 10 range ");//what input should enter
printf(" 2. password should contain atleast two upper case letters");
printf(" 3. password should contain atleast one lower case letter");
printf(" 4. password should contain two digits from(o-9)");
printf(" 5. password should contain one special charecter(@,%,#,$) ");
scanf("%s",a);//taking input from user
check(a);//calling the function that we have created above
//exit program

}
void check(char a[])//start check function with char array parameters
{
int len,i,flag1=0,flag2=0,flag3=0,flag4=0,flag5=0;//declaring all variaables and flags those are used in next
  
len=strlen(a);// calculating length of input

if(len<8||len>10) //checking length of input is in between 8-10
flag1=1;// if not goto last of function where we print error message
else
{
for(i=0;i<len;i++) //traversing input from first to last 0-n the possition of input
if((a[i]>=48&&a[i]<=58)) //checking input cantian atleast 2 digit 0-9 or not
{
flag2=flag2+1; //increament flag2 by 1 if enter digit
if(flag2==2) //chek input cantain two digits or not
break; //then gotto end and print success message
else {
flag2=1; // else gotto end and print error message
}
}
else
flag2=1; // else gotto end and print error message

for(i=0;i<len;i++)
if((a[i]>=65&&a[i]<=90)) // cheking input cantian atleast two characters are upper case( A-Z) or not
{
flag3=flag3+1; //increament flag2 by 1 if enter upper case letter
if(flag3==2) //chek input cantain two upper case letter or not
break; //then gotto end and print success message
else {
flag3=1; // else gotto end and print error message
}
}
else
flag3=1; // else gotto end and print error message
  
for(i=0;i<len;i++)
if((a[i]>=97&&a[i]<=122)) // cheking input cantians atleast one character lower case(a-z) or not
{
flag5=0; // if input cantainig one lower case letter
break; //then gotto end and print success message
}
else
flag5=1; // else set flag5=1 gotto end and print error message

for(i=0;i<len;i++)
if(a[i]=='#'||a[i]=='$'||a[i]=='%'||a[i]=='@') //cheking input catains atleast one Special symbol or not
{
flag4=0; // if input cantainig one Special symbol set flag4=0

break;
}
else
flag4=1; // else set flag4=1 and gotto end and print error message

}
if(flag1==1||flag2==1||flag3==1||flag4==1||flag5==1)//checking all above ctiteria satisfied or if satisfied print sucess message
printf(" Sorry Pease enter again your input not satisfied above mention criteria ");
else //else printf unsuccess message
printf("Your password is successfully created ");
return; // return from fucntion goto main function
}

Output 1

Enter your password that should satisfy the following criteria                                                                

1. password length should be in 8 to 10 range                                                                                 

2. password should contain atleast two upper letter                                                                           

3. password should contain atleast one lower letter                                                                           

4. password should contain two digit from(o-9)                                                                                

5. password should contain one special charecter(@,%,#,$)                                                                     

SachiN@123                                                                                                                 

Your password is successfully created

                                           

Output 2

sachin@123                                                                                                                                                                                                                                      

Sorry Pease enter again your input not satisfied above metion criteria  

Output 3

sachin123456                                                                                                                  

                                                                                                                              

Sorry Pease enter again your input not satisfied above mention criteria   

Output4

SachinN@1

Sorry Pease enter again your input not satisfied above mention created    

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote