Skip to content

Commit

Permalink
Merge pull request bcrypt-ruby#181 from bdewater/bump-default-cost-12
Browse files Browse the repository at this point in the history
Bump default cost to 12
  • Loading branch information
tjschuck authored Nov 13, 2018
2 parents a28449a + 6b3821a commit 05d8187
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ end
require 'bcrypt'

my_password = BCrypt::Password.create("my password")
#=> "$2a$10$vI8aWBnW3fID.ZQ4/zo1G.q1lRps.9cGLcZEiGDMVr5yUP1KUOYTa"
#=> "$2a$12$K0ByB.6YI2/OYrB4fQOYLe6Tv0datUVf6VZ/2Jzwm879BW5K1cHey"

my_password.version #=> "2a"
my_password.cost #=> 10
my_password.cost #=> 12
my_password == "my password" #=> true
my_password == "not my password" #=> false

my_password = BCrypt::Password.new("$2a$10$vI8aWBnW3fID.ZQ4/zo1G.q1lRps.9cGLcZEiGDMVr5yUP1KUOYTa")
my_password = BCrypt::Password.new("$2a$12$K0ByB.6YI2/OYrB4fQOYLe6Tv0datUVf6VZ/2Jzwm879BW5K1cHey")
my_password == "my password" #=> true
my_password == "not my password" #=> false
```
Expand Down Expand Up @@ -157,14 +157,14 @@ If an attacker was using Ruby to check each password, they could check ~140,000
In addition, `bcrypt()` allows you to increase the amount of work required to hash a password as computers get faster. Old
passwords will still work fine, but new passwords can keep up with the times.

The default cost factor used by bcrypt-ruby is 10, which is fine for session-based authentication. If you are using a
The default cost factor used by bcrypt-ruby is 12, which is fine for session-based authentication. If you are using a
stateless authentication architecture (e.g., HTTP Basic Auth), you will want to lower the cost factor to reduce your
server load and keep your request times down. This will lower the security provided you, but there are few alternatives.

To change the default cost factor used by bcrypt-ruby, use `BCrypt::Engine.cost = new_value`:
```ruby
BCrypt::Password.create('secret').cost
#=> 10, the default provided by bcrypt-ruby
#=> 12, the default provided by bcrypt-ruby

# set a new default cost
BCrypt::Engine.cost = 8
Expand Down
6 changes: 3 additions & 3 deletions lib/bcrypt/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module BCrypt
# A Ruby wrapper for the bcrypt() C extension calls and the Java calls.
class Engine
# The default computational expense parameter.
DEFAULT_COST = 10
DEFAULT_COST = 12
# The minimum cost supported by the algorithm.
MIN_COST = 4
# Maximum possible size of bcrypt() salts.
Expand All @@ -28,8 +28,8 @@ def self.cost
#
# Example:
#
# BCrypt::Engine::DEFAULT_COST #=> 10
# BCrypt::Password.create('secret').cost #=> 10
# BCrypt::Engine::DEFAULT_COST #=> 12
# BCrypt::Password.create('secret').cost #=> 12
#
# BCrypt::Engine.cost = 8
# BCrypt::Password.create('secret').cost #=> 8
Expand Down
2 changes: 1 addition & 1 deletion lib/bcrypt/password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module BCrypt
#
# # hash a user's password
# @password = Password.create("my grand secret")
# @password #=> "$2a$10$GtKs1Kbsig8ULHZzO1h2TetZfhO4Fmlxphp8bVKnUlZCBYYClPohG"
# @password #=> "$2a$12$C5.FIvVDS9W4AYZ/Ib37YuWd/7ozp1UaMhU28UKrfSxp2oDchbi3K"
#
# # store it safely
# @user.update_attribute(:password, @password)
Expand Down

0 comments on commit 05d8187

Please sign in to comment.