Method: BCrypt::Password.create
- Defined in:
- lib/bcrypt/password.rb
.create(secret, options = {}) ⇒ Object
Hashes a secret, returning a BCrypt::Password instance. Takes an optional :cost option, which is a logarithmic variable which determines how computational expensive the hash is to calculate (a :cost of 4 is twice as much work as a :cost of 3). The higher the :cost the harder it becomes for attackers to try to guess passwords (even if a copy of your database is stolen), but the slower it is to check users’ passwords.
Example:
@password = BCrypt::Password.create("my secret", :cost => 13)
43 44 45 46 47 |
# File 'lib/bcrypt/password.rb', line 43 def create(secret, = {}) cost = [:cost] || BCrypt::Engine.cost raise ArgumentError if cost > 31 Password.new(BCrypt::Engine.hash_secret(secret, BCrypt::Engine.generate_salt(cost), cost)) end |