use of org.keycloak.credential.hash.Pbkdf2PasswordHashProvider in project keycloak by keycloak.
the class PasswordHashingTest method testPasswordRehashedWhenCredentialImportedWithDifferentKeySize.
@Test
public void testPasswordRehashedWhenCredentialImportedWithDifferentKeySize() {
setPasswordPolicy("hashAlgorithm(" + Pbkdf2Sha512PasswordHashProviderFactory.ID + ") and hashIterations(" + Pbkdf2Sha512PasswordHashProviderFactory.DEFAULT_ITERATIONS + ")");
String username = "testPasswordRehashedWhenCredentialImportedWithDifferentKeySize";
String password = "password";
// Encode with a specific key size ( 256 instead of default: 512)
Pbkdf2PasswordHashProvider specificKeySizeHashProvider = new Pbkdf2PasswordHashProvider(Pbkdf2Sha512PasswordHashProviderFactory.ID, Pbkdf2Sha512PasswordHashProviderFactory.PBKDF2_ALGORITHM, Pbkdf2Sha512PasswordHashProviderFactory.DEFAULT_ITERATIONS, 256);
String encodedPassword = specificKeySizeHashProvider.encode(password, -1);
// Create a user with the encoded password, simulating a user import from a different system using a specific key size
UserRepresentation user = UserBuilder.create().username(username).password(encodedPassword).build();
ApiUtil.createUserWithAdminClient(adminClient.realm("test"), user);
loginPage.open();
loginPage.login(username, password);
PasswordCredentialModel postLoginCredentials = PasswordCredentialModel.createFromCredentialModel(fetchCredentials(username));
assertEquals(encodedPassword.length() * 2, postLoginCredentials.getPasswordSecretData().getValue().length());
}
Aggregations