Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot specify LongPasswordStrategy on Verifier #21

Closed
Indigo744 opened this issue Oct 17, 2019 · 6 comments
Closed

Cannot specify LongPasswordStrategy on Verifier #21

Indigo744 opened this issue Oct 17, 2019 · 6 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request
Milestone

Comments

@Indigo744
Copy link

Hello,

First of all, thanks for this library.

In my code, I need to be able to specify the LongPasswordStrategy to TruncateStrategy so the lib behave like others (in others softwares in different languages).

It all works well when saving the hash, I can do BCrypt.with(LongPasswordStrategies.truncate()).hash(...) just fine.

But when I want to verify a hash, I can't specify the strategy!
One would expect BCrypt.with(LongPasswordStrategies.truncate()).verifyer().verify(pw, hashData); to works, but alas no.

Looking quickly in the code, I can see that you simply use the withDefaults() without offering any choice to the user: https://github.com/patrickfav/bcrypt/blob/master/modules/bcrypt/src/main/java/at/favre/lib/crypto/bcrypt/BCrypt.java#L551

Is there something I'm missing? I would think the library should be able to verify its own generated hash depending on the strategy used...

Thanks.

@patrickfav
Copy link
Owner

Hi Guillaume,

No, you are absolutely right, you found a conceptional error and I don't see an easy workaround for you apart from checking by hand. I will think about a solution and update this ticket as soon as I have one.

@patrickfav patrickfav self-assigned this Oct 17, 2019
@patrickfav patrickfav added bug Something isn't working enhancement New feature or request labels Oct 17, 2019
@patrickfav patrickfav modified the milestones: v0.7.0, v0.9.0 Oct 17, 2019
@Indigo744
Copy link
Author

Thanks for your feedback.

As a workaround, we directly apply the strategy before giving the password to the lib:

byte[] passwordShort = LongPasswordStrategies.truncate().derive(password.getBytes(StandardCharsets.UTF_8));
boolean isOk = BCrypt.verifyer().verify(passwordShort, hash.getBytes()).verified;

But of course, we are still limited by the issue #22 (for which we don't have an easy workaround, excepted modifying the lib...).

@Indigo744 Indigo744 changed the title Cannot specific LongPasswordStrategy on Verifier Cannot specify LongPasswordStrategy on Verifier Oct 17, 2019
patrickfav added a commit that referenced this issue Oct 19, 2019
@patrickfav
Copy link
Owner

PR is ready (#23), @Indigo744 I invite you to do a review if you like. Otherwise I will merge it beginning of next week.

@Indigo744
Copy link
Author

Thank you. I reviewed it, looks good!

@patrickfav
Copy link
Owner

Will be released with v0.9.0

@Indigo744
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants