rails/rails — pull request #12326 by tjschuck (2013-09-23 18:53:08+00:00)
Title: Use bcrypt cost attr instead of internal constant

Currently, if you're using bcrypt-ruby in a Rails app, you can't re-set the default cost to match your own business concerns.

The current recommendation is doing something like `BCrypt::Engine::DEFAULT_COST = 12` in your `config/environments/production.rb` to set a higher cost, or a lower value if you want auth requests to be a little snappier (like for an API that requires basic auth with every request).

Re-setting the constant works, but causes a "`warning: already initialized constant DEFAULT_COST`", which makes sense, because, y'know, "constant".

A `BCrypt::Engine.cost` attribute was added to bcrypt-ruby to allow setting the value externally, defaulting internally to `DEFAULT_COST`.

See https://github.com/codahale/bcrypt-ruby/pull/63, https://github.com/codahale/bcrypt-ruby/pull/64, and https://github.com/codahale/bcrypt-ruby/pull/65.

This pull request allows users to use the correct `BCrypt::Engine.cost` attribute in their apps, and the bcrypt-ruby implementation is backwards compatible to still support resetting the constant.