Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my DFA shall accept a password of my choice.

my password shall be at least 8 characters long;

It must have a combination of characters (small and capital), digits, and special characters.



For example: my password can be described as follows

1- must be at least 8 characters

2- Must begin wiht the special symbol @

3- Must end with a capital letter

4 Must have at least 2 digits

What I have tried:

i tried to create two dimensional array and fill the row as number of accepted charcter
and the column
Posted
Updated 11-Mar-16 20:12pm
Comments
Patrice T 11-Mar-16 17:22pm    
No repost please.
VR Karthikeyan 12-Mar-16 0:27am    
What is your problem? Are you having problems in choosing the programming language? or you need ideas about password validation?

1 solution

Im assuming DFA here refers to Deterministic Finite Automaton

i think this method should suffice your question
Java
public String validatePassword(String password)
{
   if(password.length<8)
   {
      return "password length less than 8 characters";
   }
   else if(password.charAt(0)!='@')
   {
      return "password must start with a @ character";
   }
   else if(!Character.isUpperCase(password.charAt(password.length)))
  {
      return "Password must end with an Uppercase letter";
  }
  else 
  {
      int noOfDigits=0;
      for(int i=0;i<password.length;i++)>
      {
          if(Character.isDigit(password.charAt(i)))
          {
               noOfDigits++; 
          }
      }
      if(noOfDigits>=2)
      {
          return "password is valid";
      }
      else
      {
          return "password must contain at least 2 digits";
      }
  }
}

Create a String object rather than a 2d char array in java / C#
accept the password and call the above method passing the password to it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900