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
Make bcrypt rounds configurable #9044
Changes from 8 commits
0005a1f
633bc26
a5206a6
b5cd99a
add6fbc
a814df0
b23ee81
45f81ab
6c23fc2
36739e7
0c72a63
739ad16
9c38b13
f9e152f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ var bcryptCompare = Meteor.wrapAsync(bcrypt.compare); | |
// "sha-256" and then passes the digest to bcrypt. | ||
|
||
|
||
Accounts._bcryptRounds = 10; | ||
Accounts._bcryptRounds = Accounts._options.bcryptRounds || 10; | ||
|
||
// Given a 'password' from the client, extract the string that we should | ||
// bcrypt. 'password' can be one of: | ||
|
@@ -67,6 +67,20 @@ Accounts._checkPassword = function (user, password) { | |
|
||
if (! bcryptCompare(password, user.services.password.bcrypt)) { | ||
result.error = handleError("Incorrect password", false); | ||
} else if ( | ||
user.services.password.bcrypt && | ||
Accounts._bcryptRounds > | ||
Number(user.services.password.bcrypt.substring(4, 6)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this work if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While you're at it, let's just extract a helper function called something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, that code will break with a work factor above 99, but it shouldn't be possible to implement bcrypt with such a high work factor since it gets expanded geometrically (rounds = 2^[work factor]). This FreeBSD implementation of bcrypt references a maximum of 31 rounds. I'm not sure if 31 is implementation-specific or the theoretical maximum for bcrypt, but the effective maximum for most current server hardware is probably 16 or 17. From benchmarking on my MacBook Pro, hashing with a work factor of 20 takes about 2.4 minutes and 31 would take ~12 years. The rule of thumb I'm aware of (totally unattributed) is that hashing should take ~1 second with current server hardware. If I can find a source for that rule of thumb, I'll do a PR for this in the Guide. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I'm happy to move that into a helper function. At the risk of over-building but with a mind toward implementing other hashing algorithms, I'll grab both the algorithm and whatever parameters go with that algorithm. |
||
) { | ||
// password checks out, but user bcrypt may need update | ||
Meteor.defer(() => { | ||
Meteor.users.update({ _id: user._id }, { | ||
$set: { | ||
'services.password.bcrypt': | ||
bcryptHash(password, Accounts._bcryptRounds) | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
return result; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
!=
instead of just>
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, will fix