如何构建实现密码DFA的JAVA或C#程序 [英] How can I build a JAVA or C# program which implements a DFA for password

查看:73
本文介绍了如何构建实现密码DFA的JAVA或C#程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的DFA将接受我选择的密码。



我的密码长度至少为8个字符;



它必须包含字符(小号和大写字母),数字和特殊字符的组合。







例如:我的密码可以描述如下



1-必须至少8个字符



2-必须开始使用特殊符号@



3-必须以大写字母结尾



4必须至少有2位数



我尝试过:



i尝试创建二维数组并将行填充为接受的字符数

和列

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

推荐答案

Im假设DFA在这里指的是确定性有限自动机



i认为这种方法应该足以满足你的问题

Im assuming DFA here refers to Deterministic Finite Automaton

i think this method should suffice your question
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";
      }
  }
}



在java / C中创建String对象而不是2d char数组#

接受密码并调用上面的方法将密码传递给它。


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.


这篇关于如何构建实现密码DFA的JAVA或C#程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆