Skip to content

Commit 6c2297b

Browse files
ysbaddadenRX14
authored andcommittedJan 20, 2018
Fix bcrypt hard limit on passwords to 71 bytes (#5356)
Despite the original bcrypt paper claiming passwords must be a maximum of 56 bytes, the implementations are compatible to up to 72 bytes. Since increasing the limit doesn't break compatibility, but other implementations allow as many as 72 bytes, let's increase the arbitrary limitation of 51 characters (which was wrong anyway) to 72 bytes, minus the leading null byte, that is a password of 71 bytes.
1 parent ddbcf6c commit 6c2297b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed
 

‎spec/std/crypto/bcrypt_spec.cr

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe "Crypto::Bcrypt" do
1717
{5, latin1_pound_sign, "CCCCCCCCCCCCCCCCCCCCC.", "BvtRGGx3p8o0C5C36uS442Qqnrwofrq"},
1818
{5, utf8_pound_sign, "CCCCCCCCCCCCCCCCCCCCC.", "CAzSxlf0FLW7g1A5q7W/ZCj1xsN6A.e"},
1919
{5, bit8_unicode_pound_sign, "CCCCCCCCCCCCCCCCCCCCC.", "CAzSxlf0FLW7g1A5q7W/ZCj1xsN6A.e"},
20+
{5, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789012345678", "VU6N0LbtX7trKLCg4Uf8qe", "5WYPzqIUUIrkveFjCbMg/hXc592OQLK"},
2021
]
2122

2223
it "computes digest vectors" do

‎src/crypto/bcrypt.cr

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ require "./subtle"
55
# Mazières, as [presented at USENIX in
66
# 1999](https://www.usenix.org/legacy/events/usenix99/provos/provos_html/index.html).
77
#
8+
# The algorithm has a maximum password length limit of 71 characters (see
9+
# [this comment](https://security.stackexchange.com/questions/39849/does-bcrypt-have-a-maximum-password-length#answer-39851)
10+
# on stackoverflow).
11+
#
812
# Refer to `Crypto::Bcrypt::Password` for a higher level interface.
913
#
1014
# About the Cost
@@ -31,7 +35,7 @@ class Crypto::Bcrypt
3135

3236
DEFAULT_COST = 11
3337
COST_RANGE = 4..31
34-
PASSWORD_RANGE = 1..51
38+
PASSWORD_RANGE = 1..72
3539
SALT_SIZE = 16
3640

3741
private BLOWFISH_ROUNDS = 16

0 commit comments

Comments
 (0)
Please sign in to comment.