@Test
  public void testRehashedPasswordBcrypt() throws Exception {
    cpe.setPreferredEncoding("md4");
    Map<QName, Serializable> properties = new HashMap<>();
    properties.put(ContentModel.PROP_HASH_INDICATOR, (Serializable) Arrays.asList("md4"));
    properties.put(ContentModel.PROP_PASSWORD_HASH, "long hash");
    // Nothing to do.
    assertFalse(passwordHashWorker.processPasswordHash(properties));

    cpe.setPreferredEncoding("bcrypt11");
    assertTrue(passwordHashWorker.processPasswordHash(properties));
    assertEquals(
        Arrays.asList("md4", "bcrypt11"),
        RepositoryAuthenticationDao.determinePasswordHash(properties).getFirst());
  }
  @Test
  public void testGetPasswordHash() throws Exception {

    Map<QName, Serializable> properties = new HashMap<>();
    cpe.setPreferredEncoding("bcrypt10");

    try {
      RepositoryAuthenticationDao.determinePasswordHash(properties);
      fail("Should throw exception");
    } catch (AlfrescoRuntimeException are) {
      assertTrue(are.getMessage().contains("Unable to find a password for user"));
    }

    // if the PROP_PASSWORD field is the only one availble then we are using MD4
    properties.put(ContentModel.PROP_PASSWORD, "mypassword");
    Pair<List<String>, String> passwordHashed =
        RepositoryAuthenticationDao.determinePasswordHash(properties);
    assertEquals(CompositePasswordEncoder.MD4, passwordHashed.getFirst());
    assertEquals("mypassword", passwordHashed.getSecond());

    // if the PROP_PASSWORD_SHA256 field is used then we are using SHA256
    properties.put(ContentModel.PROP_PASSWORD_SHA256, "sha_password");
    passwordHashed = RepositoryAuthenticationDao.determinePasswordHash(properties);
    assertEquals(CompositePasswordEncoder.SHA256, passwordHashed.getFirst());
    assertEquals("sha_password", passwordHashed.getSecond());

    properties.put(ContentModel.PROP_HASH_INDICATOR, null);
    // If the indicator is NULL then it still uses the old password field
    passwordHashed = RepositoryAuthenticationDao.determinePasswordHash(properties);
    assertEquals(CompositePasswordEncoder.SHA256, passwordHashed.getFirst());
    assertEquals("sha_password", passwordHashed.getSecond());

    properties.put(ContentModel.PROP_HASH_INDICATOR, new ArrayList<String>(0));
    // If the indicator doesn't have a value
    passwordHashed = RepositoryAuthenticationDao.determinePasswordHash(properties);
    assertEquals(CompositePasswordEncoder.SHA256, passwordHashed.getFirst());
    assertEquals("sha_password", passwordHashed.getSecond());

    // Now it uses the correct property
    properties.put(ContentModel.PROP_HASH_INDICATOR, (Serializable) Arrays.asList("myencoding"));
    properties.put(ContentModel.PROP_PASSWORD_HASH, "hashed this time");
    passwordHashed = RepositoryAuthenticationDao.determinePasswordHash(properties);
    assertEquals(Arrays.asList("myencoding"), passwordHashed.getFirst());
    assertEquals("hashed this time", passwordHashed.getSecond());
  }