char[] expectedPassword = ((UserAccount) account).password;
char[] suppliedPassword = ((PasswordCredential) credential).getPassword();
return Arrays.equals(expectedPassword, suppliedPassword);
} else if (credential instanceof DigestCredential) {
DigestCredential digCred = (DigestCredential) credential;
MessageDigest digest = null;
try {
digest = digCred.getAlgorithm().getMessageDigest();
digest.update(account.getPrincipal().getName().getBytes(UTF_8));
digest.update((byte) ':');
digest.update(digCred.getRealm().getBytes(UTF_8));
digest.update((byte) ':');
char[] expectedPassword = ((UserAccount) account).password;
digest.update(new String(expectedPassword).getBytes(UTF_8));
return digCred.verifyHA1(HexConverter.convertToHexBytes(digest.digest()));
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException("Unsupported Algorithm", e);
} finally {
digest.reset();
}