MCPcopy Create free account
hub / github.com/bcrypt-ruby/bcrypt-ruby / generate_salt

Method generate_salt

lib/bcrypt/engine.rb:81–95  ·  view source on GitHub ↗

Generates a random salt with a given computational cost.

(cost = self.cost)

Source from the content-addressed store, hash-verified

79
80 # Generates a random salt with a given computational cost.
81 def self.generate_salt(cost = self.cost)
82 cost = cost.to_i
83 if cost > 0
84 if cost < MIN_COST
85 cost = MIN_COST
86 end
87 if RUBY_PLATFORM == "java"
88 Java.bcrypt_jruby.BCrypt.gensalt(cost)
89 else
90 __bc_salt("$2a$", cost, OpenSSL::Random.random_bytes(MAX_SALT_LENGTH))
91 end
92 else
93 raise Errors::InvalidCost.new("cost must be numeric and > 0")
94 end
95 end
96
97 # Returns true if +salt+ is a valid bcrypt() salt, false if not.
98 def self.valid_salt?(salt)

Callers 3

createMethod · 0.80
engine_spec.rbFile · 0.80
password_spec.rbFile · 0.80

Calls 2

costMethod · 0.95
gensaltMethod · 0.80

Tested by

no test coverage detected