示例#1
0
 public static void test3() {
   try {
     String pwd = "123";
     String passHash1 = PasswordHash.createHash(pwd);
     String passHash2 = PasswordHash.createHash(pwd);
     boolean flag1 = PasswordHash.validatePassword(pwd, passHash1);
     boolean flag2 = PasswordHash.validatePassword(pwd, passHash2);
     System.out.println(flag1);
     System.out.println(flag2);
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
   } catch (InvalidKeySpecException e) {
     e.printStackTrace();
   }
 }
示例#2
0
 public static void test2() {
   try {
     String pass1 = PasswordHash.createHash("123");
     System.out.println(pass1);
     String s =
         "1000:7af36fc2d12dcf5b7104dfc47c1ac1fd6e7b12681bede0c5:bcbcab2c9f6689fb2f738e6fe98201089b65d99e037462c5";
     System.out.println(s.length());
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
   } catch (InvalidKeySpecException e) {
     e.printStackTrace();
   }
 }
示例#3
0
  public static void test1() {
    try {
      // Print out 10 hashes
      for (int i = 0; i < 10; i++) {

        String hash = PasswordHash.createHash("p\r\nassw0Rd!");
        System.out.println(hash + " ~ " + hash.length());
      }

      // Test password validation
      boolean failure = false;
      System.out.println("Running tests...");
      for (int i = 0; i < 100; i++) {
        String password = "" + i;
        String hash = createHash(password);
        String secondHash = createHash(password);
        if (hash.equals(secondHash)) {
          System.out.println("FAILURE: TWO HASHES ARE EQUAL!");
          failure = true;
        }
        String wrongPassword = "" + (i + 1);
        if (validatePassword(wrongPassword, hash)) {
          System.out.println("FAILURE: WRONG PASSWORD ACCEPTED!");
          failure = true;
        }
        if (!validatePassword(password, hash)) {
          System.out.println("FAILURE: GOOD PASSWORD NOT ACCEPTED!");
          failure = true;
        }
      }
      if (failure) System.out.println("TESTS FAILED!");
      else System.out.println("TESTS PASSED!");
    } catch (Exception ex) {
      System.out.println("ERROR: " + ex);
    }
  }