PHPass { public boolean CheckPassword(String password, String storedHash) { String hash = cryptPrivate(password, storedHash); MessageDigest md = null; if (hash.startsWith("*")) { if (storedHash.startsWith("$6$")) { try { md = MessageDigest.getInstance("SHA-512"); } catch (NoSuchAlgorithmException e) { md = null; } } if (md == null && storedHash.startsWith("$5$")) { try { md = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { md = null; } } if (md == null && storedHash.startsWith("$2")) { return BCrypt.checkpw(password, storedHash); } if (md == null && storedHash.startsWith("$1$")) { try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { md = null; } } if (md != null) { hash = new String(md.digest(password.getBytes())); } } return hash.equals(storedHash); } PHPass(int iterationCountLog2); String HashPassword(String password); boolean CheckPassword(String password, String storedHash);  }
@Test public final void testCheckPassword_correct() { boolean check = phpass.CheckPassword(correct, this.hashed); Assert.assertTrue(check); }
@Test public final void testCheckPassword_wrong() { boolean check = phpass.CheckPassword(wrong, this.hashed); Assert.assertFalse(check); }
@Test public final void testCheckPassword_givenhash_correct() { boolean check = phpass.CheckPassword(correct, hash); Assert.assertTrue(check); }
@Test public final void testCheckPassword_givenhash_wrong() { boolean check = phpass.CheckPassword(wrong, hash); Assert.assertFalse(check); }
@Test public final void testCheckPassword_nationalCharacters_correct() { boolean check = phpass.CheckPassword(correctpl, hashpl); assertTrue(check); }
@Test public final void testCheckPassword_nationalCharacters_wrong() { boolean check = phpass.CheckPassword(wrongpl, hashpl); assertFalse(check); }