PasswordHash { public boolean matches(String secret) { byte[] candidate; try { candidate = digest(salt, algorithm, secret); } catch (NoSuchAlgorithmException e) { log.error(e.getMessage()); return false; } return Arrays.equals(candidate, hash); } private  PasswordHash();  PasswordHash(String algorithm, byte[] salt, byte[] hash);  PasswordHash(String algorithm, String salt, String hash);  PasswordHash(String password); boolean matches(String secret); byte[] getHash(); String getHashString(); byte[] getSalt(); String getSaltString(); String getAlgorithm(); static String getDefaultAlgorithm();  }
@Test public void testMatches() throws NoSuchAlgorithmException, UnsupportedEncodingException { System.out.println("matches"); final String secret = "Clark Kent is Superman"; MessageDigest digest = MessageDigest.getInstance("MD5"); PasswordHash hash = new PasswordHash(null, null, digest.digest(secret.getBytes(Constants.DEFAULT_ENCODING))); boolean result = hash.matches(secret); assertTrue("Old unsalted 1-trip MD5 hash", result); }