Method: BCrypt::Engine.generate_salt
- Defined in:
- lib/bcrypt/engine.rb
.generate_salt(cost = self.cost) ⇒ Object
Generates a random salt with a given computational cost.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/bcrypt/engine.rb', line 81 def self.generate_salt(cost = self.cost) cost = cost.to_i if cost > 0 if cost < MIN_COST cost = MIN_COST end if RUBY_PLATFORM == "java" Java.bcrypt_jruby.BCrypt.gensalt(cost) else __bc_salt("$2a$", cost, OpenSSL::Random.random_bytes(MAX_SALT_LENGTH)) end else raise Errors::InvalidCost.new("cost must be numeric and > 0") end end |