Generates a random salt with a given computational cost.
(cost = self.cost)
| 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) |
no test coverage detected