密码要求:
1.长度超过8位
2.包括大小写字母.数字.其它符号,以上四种至少三种
3.不能有相同长度超2的子串重复
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scanner=new Scanner(System.in); String s; while(scanner.hasNext()){ s=scanner.next(); if(s.length()>8&&hasNoRepeat(s)&&hasThree(s)){ System.out.println("OK"); }else{ System.out.println("NG"); } } } public static boolean hasNoRepeat(String s){ String temp; for(int i=0;i<s.length();i++) for(int j=i+2;j<s.length();j++){ temp=s.substring(i,j); if(s.indexOf(temp, j+1)!=-1){ return false; } } return true; } public static boolean hasThree(String s){ int count=0; boolean hasNum=false; boolean hasLowChar=false; boolean hasHighChar=false; boolean hasOther=false; char c; for(int i=0;i<s.length();i++){ c=s.charAt(i); if('0'<=c&&c<='9'){ if(!hasNum){ hasNum=true; count++; } }else if('a'<=c&&c<='z'){ if(!hasLowChar){ hasLowChar=true; count++; } }else if('A'<=c&&c<='Z'){ if(!hasHighChar){ if(!hasHighChar){ hasHighChar=true; count++; } } }else{ if(!hasOther){ hasOther=true; count++; } } if(count>=3){ return true; } } return false; } }
密码验证合格程序
最新推荐文章于 2023-04-18 20:05:46 发布