bcrypt-ruby wraps the OpenBSD bcrypt algorithm so Ruby applications can store and verify secure password hashes.
Overview
bcrypt-ruby is a Ruby gem that binds the OpenBSD bcrypt() password hashing function. It lets web applications store one-way password digests instead of plaintext secrets, reducing damage if a database is copied.
The library automatically generates and stores salts with hashes. Salts defeat precomputed rainbow tables by forcing attackers to hash guesses per salt. bcrypt() is deliberately slow compared with fast digests like MD5, shrinking how many guesses an attacker can test per second. You can raise the cost factor as machines get faster while old hashes remain valid.
The default cost factor is 12, which suits session-based authentication; stateless schemes such as HTTP Basic Auth may use a lower cost to limit server load. BCrypt::Password and related APIs cover creating accounts and authenticating users; Rails 3 and later ship ActiveModel::SecurePassword built on bcrypt-ruby.
The gem installs on JRuby, Windows RubyInstaller builds with DevKit, and typical BSD, macOS, and Linux systems with a compiler. bcrypt() is the default password storage approach in OpenBSD.
Key features
- OpenBSD bcrypt algorithm binding
- Automatic per-password salts
- Adjustable work cost factor
- BCrypt::Password hash objects
- Rails SecurePassword integration
- JRuby and CRuby support
- Windows RubyInstaller compatibility
- Slow hashing against brute force
Use cases
- Storing user passwords in Ruby web apps
- Authenticating login credentials safely
- Rails applications using has_secure_password
- Increasing hash cost over time
- Replacing fast insecure password digests