Skip to content

Commit

Permalink
fix: fix base64 encoding
Browse files Browse the repository at this point in the history
chore: bump version to 1.5.1
ci(docker): use 1.5.1 as default version of keycloak-bcrypt
  • Loading branch information
leroyguillaume committed Jul 24, 2022
1 parent c00f103 commit 00f2e36
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
keycloak_bcrypt_version:
description: Keycloak BCrypt version
required: true
default: 1.5.0
default: 1.5.1

name: Docker

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = "com.github.leroyguillaume"
version = "1.5.0"
version = "1.5.1"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ public PasswordCredentialModel encodedCredential(final String rawPassword, final
@Override
public String encode(final String rawPassword, final int iterations) {
final int cost = iterations == -1 ? defaultIterations : iterations;
final byte[] hash = BCrypt.with(BCrypt.Version.VERSION_2Y).hashToString(cost, rawPassword.toCharArray())
.getBytes();
return Base64.getEncoder().encodeToString(hash);
return BCrypt.with(BCrypt.Version.VERSION_2Y).hashToString(cost, rawPassword.toCharArray());
}

@Override
Expand All @@ -50,11 +48,8 @@ public void close() {

@Override
public boolean verify(final String rawPassword, final PasswordCredentialModel credential) {
final String base64EncodedHash = credential.getPasswordSecretData().getValue();
final String base64DecodedHash = new String(Base64.getDecoder().decode(base64EncodedHash));

return BCrypt.verifyer(BCrypt.Version.VERSION_2Y)
.verify(rawPassword.toCharArray(), base64DecodedHash.toCharArray())
.verified;
final String hash = credential.getPasswordSecretData().getValue();
final BCrypt.Result verifier = BCrypt.verifyer().verify(rawPassword.toCharArray(), hash.toCharArray());
return verifier.verified;
}
}

0 comments on commit 00f2e36

Please sign in to comment.