コード例 #1
0
 @Test
 public void testPlain1() throws Exception {
   PasswordValidator sut = new PasswordValidator(true);
   assertTrue(sut.validate("1", "1"));
   assertFalse(sut.validate("1", "2"));
   assertFalse(sut.validate("2", "1"));
 }
コード例 #2
0
 @Test
 public void test6() throws Exception {
   assertFalse(sut.validate("0", "{MD5}xMpCOKC5I4INzFCab3WEmw=="));
   assertFalse(sut.validate("2", "{MD5}xMpCOKC5I4INzFCab3WEmw=="));
   assertFalse(sut.validate("3", "{MD5}xMpCOKC5I4INzFCab3WEmw=="));
   // проверка, на case-sensitive
   assertFalse(sut.validate("1", "{MD5}XMpCOKC5I4INzFCab3WEmw=="));
 }
コード例 #3
0
  @Ignore
  @Test(timeout = 3000)
  public void testPerfSHA1() throws Exception {
    long t = System.currentTimeMillis();

    for (int i = 0; i < 100000; i++) {
      sut.validate("1", "{SHA-1}356a192b7913b04c54574d18c28d46e6395428ab", BinEncoding.HEX);
      sut.validate("0", "{SHA-1}356a192b7913b04c54574d18c28d46e6395428ab", BinEncoding.HEX);
      sut.validate("1", "{SHA-1}NWoZK3kTsExUV00Ywo1G5jlUKKs=");
      sut.validate("0", "{SHA-1}NWoZK3kTsExUV00Ywo1G5jlUKKs=");

      sut.calculateEncodedDigest("1", "sha-1", BinEncoding.HEX);
      sut.calculateEncodedDigest("1", "sha-1");
    }
    System.out.println(System.currentTimeMillis() - t + " ms");
  }
コード例 #4
0
  @Ignore
  @Test(timeout = 3000)
  public void testPerfMD5() throws Exception {
    long t = System.currentTimeMillis();

    for (int i = 0; i < 100000; i++) {
      sut.validate("1", "{MD5}c4ca4238a0b923820dcc509a6f75849b", BinEncoding.HEX);
      sut.validate("0", "{MD5}c4ca4238a0b923820dcc509a6f75849b", BinEncoding.HEX);
      sut.validate("1", "{MD5}xMpCOKC5I4INzFCab3WEmw==");
      sut.validate("0", "{MD5}xMpCOKC5I4INzFCab3WEmw==");

      sut.calculateEncodedDigest("1", "md5", BinEncoding.HEX);
      sut.calculateEncodedDigest("1", "md5");
    }
    System.out.println(System.currentTimeMillis() - t + " ms");
  }
コード例 #5
0
  /**
   * Attempts to load all Spring application context XML files to verify proper wiring.
   *
   * @throws Exception On test failure.
   */
  @Test(groups = {"passtest"})
  public void testSpringWiring() throws Exception {
    final ClassPathXmlApplicationContext context =
        new ClassPathXmlApplicationContext(
            new String[] {
              "/spring-context.xml",
            });
    AssertJUnit.assertTrue(context.getBeanDefinitionCount() > 0);

    final PasswordValidator validator =
        new PasswordValidator(new ArrayList<Rule>(context.getBeansOfType(Rule.class).values()));
    final PasswordData pd = new PasswordData(new Password("springtest"));
    pd.setUsername("springuser");

    final RuleResult result = validator.validate(pd);
    AssertJUnit.assertNotNull(result);
  }
コード例 #6
0
ファイル: AddAccountForm.java プロジェクト: dbt/jamm
  /**
   * Validates the password. It does this by checking to make sure the password isn't null or an
   * empty string, and then calls a method on PasswordValidator to do the validation.
   *
   * @see jamm.webapp.PasswordValidator#validatePassword
   * @param mapping The action mapping.
   * @param request The servlet request.
   * @return Any errors.
   */
  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();
    if ((mName == null) || mName.equals("")) {
      errors.add("name", new ActionError("add_account.error.no_name"));
    }

    if (!PasswordValidator.validatePassword(mPassword, mRetypedPassword, errors)) {
      clearPasswords();
    }

    return errors;
  }
コード例 #7
0
  public JSONObject validatePwd(String pwd) {

    //        Properties props = new Properties();
    //        try{
    ////            InputStream msgProp = new FileInputStream("/messages.properties");
    //            InputStream msgProp =
    // PwdValidator.class.getClassLoader().getResourceAsStream("/messages.properties");
    //            props.load(msgProp);
    //        } catch (Exception e) {
    //                e.printStackTrace();
    //        }
    //        MessageResolver resolver = new MessageResolver(props);

    // password must be between 8 and 16 chars long
    LengthRule lengthRule = new LengthRule(6, 16);

    // control allowed characters
    CharacterCharacteristicsRule charRule = new CharacterCharacteristicsRule();
    // require at least 1 digit in passwords
    charRule.getRules().add(new DigitCharacterRule(1));
    // require at least 1 non-alphanumeric char
    charRule.getRules().add(new NonAlphanumericCharacterRule(1));
    // require at least 1 upper case char
    charRule.getRules().add(new UppercaseCharacterRule(1));
    // require at least 1 lower case char
    charRule.getRules().add(new LowercaseCharacterRule(1));
    // require at least 3 of the previous rules be met
    charRule.setNumberOfCharacteristics(4);

    // group all rules together in a List
    List<Rule> ruleList = new ArrayList<Rule>();
    ruleList.add(lengthRule);
    ruleList.add(charRule);

    PasswordValidator validator = new PasswordValidator(ruleList);
    //        PasswordValidator validator = new PasswordValidator(resolver, ruleList);
    PasswordData passwordData = new PasswordData(new Password(pwd));

    JSONObject msg = new JSONObject();
    try {
      msg.put("tooShort", false);
      msg.put("noCaps", false);
      msg.put("noSpecials", false);
      msg.put("noDigits", false);
    } catch (JSONException e) {
      e.printStackTrace();
    }

    RuleResult result = validator.validate(passwordData);
    if (result.isValid()) {
      return msg;
    } else {
      ListIterator<RuleResultDetail> resultDetailIterator = result.getDetails().listIterator();
      while (resultDetailIterator.hasNext()) {
        RuleResultDetail ruleResultDetail = resultDetailIterator.next();
        String errorCodeString = ruleResultDetail.getErrorCode();
        if (errorCodeString.equals("TOO_SHORT")) {
          try {
            msg.put("tooShort", true);
          } catch (JSONException e) {
            e.printStackTrace();
          }
        } else if (errorCodeString.equals("INSUFFICIENT_CHARACTERS")) {
          if (ruleResultDetail.getParameters().containsValue("digit")) {
            try {
              msg.put("noDigits", true);
            } catch (JSONException e) {
              e.printStackTrace();
            }
          } else if (ruleResultDetail.getParameters().containsValue("non-alphanumeric")) {
            try {
              msg.put("noSpecials", true);
            } catch (JSONException e) {
              e.printStackTrace();
            }
          } else if (ruleResultDetail.getParameters().containsValue("uppercase")) {
            try {
              msg.put("noCaps", true);
            } catch (JSONException e) {
              e.printStackTrace();
            }
          }
        }
      }
      return msg;
    }
  }
コード例 #8
0
 @Test
 public void test11() throws Exception {
   assertEquals(
       "{SHA-1}356A192B7913B04C54574D18C28D46E6395428AB",
       sut.calculateEncodedDigest("1", "sha-1", BinEncoding.HEX));
 }
コード例 #9
0
 @Test
 public void test10() throws Exception {
   assertEquals("{MD5}xMpCOKC5I4INzFCab3WEmw==", sut.calculateEncodedDigest("1", "md5"));
 }
コード例 #10
0
 @Test
 public void test9() throws Exception {
   assertEquals(
       "{MD5}C4CA4238A0B923820DCC509A6F75849B",
       sut.calculateEncodedDigest("1", "md5", BinEncoding.HEX));
 }
コード例 #11
0
 @Test(expected = IllegalArgumentException.class)
 public void test8() throws Exception {
   assertTrue(
       sut.validate("1", "{SHA-2}356a192b7913b04c54574d18c28d46e6395428ab", BinEncoding.HEX));
 }
コード例 #12
0
 @Test
 public void test7() throws Exception {
   assertTrue(
       sut.validate("1", "{SHA-1}356a192b7913b04c54574d18c28d46e6395428ab", BinEncoding.HEX));
 }
コード例 #13
0
 @Test
 public void test5() throws Exception {
   assertTrue(sut.validate("1", "{MD5}xMpCOKC5I4INzFCab3WEmw=="));
 }
コード例 #14
0
 @Test
 public void test4() throws Exception {
   assertFalse(sut.validate("0", "{MD5}c4ca4238a0b923820dcc509a6f75849b", BinEncoding.HEX));
   assertFalse(sut.validate("2", "{MD5}c4ca4238a0b923820dcc509a6f75849b", BinEncoding.HEX));
   assertFalse(sut.validate("3", "{MD5}c4ca4238a0b923820dcc509a6f75849b", BinEncoding.HEX));
 }
コード例 #15
0
 @Test
 public void test3() throws Exception {
   assertTrue(sut.validate("1", "{MD5}c4ca4238a0b923820dcc509a6f75849b", BinEncoding.HEX));
 }