2016-07-26 4 views

答えて

2

が文字列の大文字、小文字、数&特殊文字を持っている場合はブール値を返し、次のスニペットを見つけてくださいwebdriverをセレンの文字の上を検証する方法:

String Password = "Abcd123$"; 
public static boolean UpperCasePresence(String Password) 
{ 

    int UC = 0; 
    for(int i=0;i<Password.length();i++) 
    { 
     if(Character.isUpperCase(Password.charAt(i))) 
     { 
      UC++; 
     } 
    } 
    if(UC>=1) 
    { 
     System.out.println("Upper Case Count :" + UC); 
     return true; 
    } 
    else 
    { 
     System.out.println("Upper Case Count is " + UC); 
     return false; 
    } 
} 


public static boolean LowerCasePresence(String Password) 
{ 
    int LC = 0; 
    for(int i=0;i<Password.length();i++) 
    { 
     if(Character.isLowerCase(Password.charAt(i))) 
     { 
      LC++; 
     } 
    } 
    if(LC>=1) 
    { 
     System.out.println("Lower Case Count :" + LC); 
     return true; 
    } 
    else 
    { 
     System.out.println("Lower Case Count is" + LC); 
     return false; 
    } 
} 

public static boolean SpecialCharPresence(String Password) 
{ 

    Pattern p = Pattern.compile("[^A-Za-z0-9]"); 
    Matcher m = p.matcher(Password); 
    boolean b = m.find(); 
    if (b == true) 
    { 
     System.out.println("Special character are there in Password"); 
     return true; 
    } 
    else 
    { 
     System.out.println("There is no special char in Password"); 
     return false; 
    } 


} 


public static boolean NumberPresence(String Password) 
{ 

    Pattern p = Pattern.compile("([0-9])"); 
    Matcher m = p.matcher(Password); 
    boolean b = m.find(); 
    if (b == true) 
    { 
     System.out.println("Numbers are there in Password "); 
     return true; 
    } 
    else 
    { 
     System.out.println("There is no Numbers in Password"); 
     return false; 
    } 


} 

これを検証に使用します。私はあなたが尋ねたことを理解することを望む。疑問があればコメントしてください。


 if(PWD.length()>=6) 
     { 
     System.out.println("Password is greater than 6 char"); 
     if(UpperCasePresence(PWD)) 
     { 
      System.out.println("Password has Upper case letter"); 

      if(LowerCasePresence(PWD)) 
      { 
       System.out.println("Password has Lower case letter"); 
       if(SpecialCharPresence(PWD)) 
       { 
        System.out.println("Password has Special Character"); 
        if(NumberPresence(PWD)) 
        { 
         System.out.println("Password has Number"); 
         System.out.println("Password Matches all Conditions"); 
        } 
        else 
        { 
         System.out.println("Password doesnot have Number"); 
        } 


       } 
       else 
       { 
        System.out.println("Password doesnot have Special Characters"); 
       } 
      } 
      else 
      { 
       System.out.println("Password doesnot have Lower Case Letters"); 
      } 
     } 
     else 
     { 
      System.out.println("Password doesnot have Upper Case Letters"); 
     } 
    } 
    else 
    { 
     System.out.println("Password Length is" + PWD.length()); 
    } 

使用このブロックあなたの@Test内側と外側のメソッドを配置し、それらを呼び出す場合。また、必要に応じてprintlnステートメントをAssertステートメントに置き換えます。

+0

この回答が役に立つとわかったら、投票してください。他の人はそれを利用することができます。 –

0

それは以下のようにRegexを使用してちょうど1つのライナーソリューションです: -

String password = "Abcd123$"; 
String regex = "((?=.*\\d)(?=.*[a-zA-Z])(?=.*[~'[email protected]#$%?\\\\/&*\\]|\\[=()}\"{+_:;,.><'-])).{8,}"; 
System.out.println(password.matches(regex)); 

: - seleniumのない役割がありません。それはちょうどJavaのものです。

希望するもの:

関連する問題