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

Add support for Bcrypt algorithm version 2y #12447

Merged
merged 1 commit into from
Sep 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add support for Bcrypt algorithm version 2y
This is related to #11595 and the suggestion from @Blacksmoke16 to
also add support for version 2y.

As per https://en.wikipedia.org/wiki/Bcrypt, it seems 2y is limited
to hashes generated by the fixed PHP algorithm.
docelic committed Sep 5, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit be714ab1e965d3bdfe8cb7358fa4ca9e0afc40f8
4 changes: 4 additions & 0 deletions spec/std/crypto/bcrypt/password_spec.cr
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@ describe "Crypto::Bcrypt::Password" do
password2 = Crypto::Bcrypt::Password.new("$2$04$ZsHrsVlj.dsmn74Az1rjmeE/21nYRC0vB5LPjG7ySBfi6lRaO/P22")
password2a = Crypto::Bcrypt::Password.new("$2a$04$ZsHrsVlj.dsmn74Az1rjmeE/21nYRC0vB5LPjG7ySBfi6lRaO/P22")
password2b = Crypto::Bcrypt::Password.new("$2b$04$ZsHrsVlj.dsmn74Az1rjmeE/21nYRC0vB5LPjG7ySBfi6lRaO/P22")
password2y = Crypto::Bcrypt::Password.new("$2y$04$ZsHrsVlj.dsmn74Az1rjmeE/21nYRC0vB5LPjG7ySBfi6lRaO/P22")

it "verifies password is incorrect" do
(password.verify "wrong").should be_false
@@ -73,5 +74,8 @@ describe "Crypto::Bcrypt::Password" do
it "verifies password version 2b is correct (#11584)" do
(password2b.verify "secret").should be_true
end
it "verifies password version 2y is correct" do
(password2y.verify "secret").should be_true
end
end
end
2 changes: 1 addition & 1 deletion src/crypto/bcrypt/password.cr
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ require "../subtle"
#
# See `Crypto::Bcrypt` for hints to select the cost when generating hashes.
class Crypto::Bcrypt::Password
private SUPPORTED_VERSIONS = ["2", "2a", "2b"]
private SUPPORTED_VERSIONS = ["2", "2a", "2b", "2y"]

# Hashes a password.
#