title: Java Regex expressions for Passwords
body: <p>I've just created this class for a password validation</p>
  
  <pre><code> /* 
   *  ^                         Start anchor
   *  (?=.*[A-Z].*[A-Z])        Ensure string has two uppercase letters.
   *  (?=.*[!@#$&amp;*])            Ensure string has one special case letter.
   *  (?=.*[0-9].*[0-9])        Ensure string has two digits.
   *  (?=.*[a-z].*[a-z].*[a-z]) Ensure string has three lowercase letters.
   *  .{8}                      Ensure string is of length 8.
   *  $                         End anchor.
   */
  public class PasswordUtils {
  
      private static final String PWD_REGEX = "^(?=.*[A-Z].*[A-Z])(?=.*[!@#$&amp;*])(?=.*[0-9].*[0-9])(?=.*[a-z].*[a-z].*[a-z])";
  
      /**
       * Non instantiable.
       */
      private PasswordUtils() {
          throw new AssertionError("Non instantiable");
      }
  
      public static boolean match (String pwd1, String pwd2) {
          return StringUtils.equals(pwd1, pwd2);
      }
  
      public static boolean isStrong(String password){
          return password.matches(PWD_REGEX);
       }
  }
  </code></pre>
  
  <p>Then this Junit, but it seems that the pwd does not match the requirements
  of the regular expression</p>
  
  <pre><code>private final String PWD6 = "Pi89pR&amp;s";
  
  @Test
  public void testStrong () {
      assertTrue(PasswordUtils.isStrong(PWD6));
  }
  </code></pre>