### Question:
PhpBB implements EncryptionMethod { @Override public boolean comparePassword(String password, HashedPassword hashedPassword, String name) { final String hash = hashedPassword.getHash(); if (HashUtils.isValidBcryptHash(hash)) { return bCrypt2y.comparePassword(password, hashedPassword, name); } else if (hash.length() == 34) { return PhpassSaltedMd5.phpbb_check_hash(password, hash); } else { return PhpassSaltedMd5.md5(password).equals(hash); } }  @Override HashedPassword computeHash(String password, String name); @Override String computeHash(String password, String salt, String name); @Override boolean comparePassword(String password, HashedPassword hashedPassword, String name); @Override String generateSalt(); @Override boolean hasSeparateSalt();  }### Answer:
@Test public void shouldMatchPhpassSaltedMd5Hashes() { Map<String, String> givenHashes = ImmutableMap.of( "password", "$H$7MaSGQb0xe3Fp/a.Q.Ewpw.UKfCv.t0", "PassWord1", "$H$7ESfAVjzqajC7fJFcZKZIhyds41MuW.", "&^%te$t?Pw@_", "$H$7G65SXRPbR69jLg.qZTjtqsw36Ciw7.", "âË_3(íù*", "$H$7Brcg8zO9amr2SHVgz.pFxprDu40v4/"); PhpBB phpBB = new PhpBB(); for (Map.Entry<String, String> hashEntry : givenHashes.entrySet()) { if (!phpBB.comparePassword(hashEntry.getKey(), new HashedPassword(hashEntry.getValue()), null)) { fail("Hash comparison for '" + hashEntry.getKey() + "' failed"); } } }
@Test public void shouldMatchUnsaltedMd5Hashes() { Map<String, String> givenHashes = ImmutableMap.of( "password", "5f4dcc3b5aa765d61d8327deb882cf99", "PassWord1", "f2126d405f46ed603ff5b2950f062c96", "&^%te$t?Pw@_", "0833dcd2bc741f90c46bbac5498fd08f", "âË_3(íù*", "e7412bf1a9d312dc2901c3101a097abe"); PhpBB phpBB = new PhpBB(); for (Map.Entry<String, String> hashEntry : givenHashes.entrySet()) { if (!phpBB.comparePassword(hashEntry.getKey(), new HashedPassword(hashEntry.getValue()), null)) { fail("Hash comparison for '" + hashEntry.getKey() + "' failed"); } } }