You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pwd = "5}rmfd+@\"6?5Yor{qgS)UGtn,T&V=h3)KYT.joWv6*Da\"iP\"t)ChCj!A[m}/)rW_:Q?(f~2fn(<(f)b_3+_kE$fV66YUz=#M7fjC<=R6" pwd1 = pwd.sub("R6", "R9") #substitutes last 2 chars of pwd from R6 to R9
BCrypt::Engine.hash_secret(pwd, bcrypt.salt) == BCrypt::Engine.hash_secret(pwd1, bcrypt.salt) #returns true when it should return false
pwd2 = pwd.sub("5}", "6}") #substitutes first 2 chars of pwd from 5} to 6}
BCrypt::Engine.hash_secret(pwd, bcrypt.salt) == BCrypt::Engine.hash_secret(pwd2, bcrypt.salt) #returns false as expected
Your password is longer than bcrypt supports. (Note: bcrypt itself, not bcrypt-ruby.)
Anything after 72 bytes is truncated, so any two passwords for which the first 72 bytes match will pass, even if they're different after that. Since you're changing the last 2 characters of a 104 character string, they fall outside of this window.
If you want to reject passwords longer than 72 bytes to avoid this issue, you should add it to your app code. For example, this is what Rails' has_secure_password does. (Docs here.)
If you Google something like "bcrypt 72", you'll see that this is an issue common to most bcrypt implementations — it's part of the design of it. See also: bcrypt#User Input
@tjschuck thanks for explanation. The logical question now is, is there a alternative encryptor to BCrypt that is at least as good if not better than BCrypte and is it worth using any one of them
If you want to consider alternatives, I'll refer you to the "Password handling" section of Cryptographic Right Answers:
In order of preference, use scrypt, argon2, bcrypt, and then if nothing else is available PBKDF2. [...] But, seriously: you can throw a dart at a wall to pick one of these.
Activity
tjschuck commentedon Aug 13, 2019
Your password is longer than bcrypt supports. (Note: bcrypt itself, not bcrypt-ruby.)
Anything after 72 bytes is truncated, so any two passwords for which the first 72 bytes match will pass, even if they're different after that. Since you're changing the last 2 characters of a 104 character string, they fall outside of this window.
If you want to reject passwords longer than 72 bytes to avoid this issue, you should add it to your app code. For example, this is what Rails'
has_secure_passworddoes. (Docs here.)If you Google something like "bcrypt 72", you'll see that this is an issue common to most bcrypt implementations — it's part of the design of it. See also: bcrypt#User Input
daya commentedon Aug 13, 2019
@tjschuck thanks for explanation. The logical question now is, is there a alternative encryptor to BCrypt that is at least as good if not better than BCrypte and is it worth using any one of them
tjschuck commentedon Aug 13, 2019
bcrypt is still perfectly good. 72 bytes of entropy for your password is — dare I say — more than enough.
I saw you linked this to an issue in a Devise extension — note that Devise also validates that passwords should be < 72, like Rails' has_secure_password.
If you want to consider alternatives, I'll refer you to the "Password handling" section of Cryptographic Right Answers:
daya commentedon Aug 14, 2019
Thanks @tjschuck