Class: MultiPassword::Strategies::SCrypt
- Inherits:
-
Object
- Object
- MultiPassword::Strategies::SCrypt
- Includes:
- MultiPassword::Strategy
- Defined in:
- lib/multi_password/strategies/scrypt.rb
Instance Method Summary collapse
- #create(password, options = {}) ⇒ Object
- #validate_options(options) ⇒ Object
- #verify(password, encrypted_password) ⇒ Object
Methods included from MultiPassword::Strategy
Instance Method Details
#create(password, options = {}) ⇒ Object
11 12 13 |
# File 'lib/multi_password/strategies/scrypt.rb', line 11 def create(password, = {}) ::SCrypt::Password.create(password, ()).to_s end |
#validate_options(options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/multi_password/strategies/scrypt.rb', line 19 def () return if .empty? key_len = [:key_len] max_time = [:max_time] max_mem = [:max_mem] if key_len && (!key_len.is_a?(Integer) || key_len < 16 || key_len > 512) raise InvalidOptions.new('scrypt', 'key_len must be an integer between 16 and 512') end if max_time && (!max_time.is_a?(Integer) || max_time < 0 || max_time > 2) raise InvalidOptions.new('scrypt', 'max_time must be an integer between 0 and 2') end if max_mem && (!max_mem.is_a?(Numeric) || max_mem < 0 || max_mem > 256) raise InvalidOptions.new('scrypt', 'max_mem must be a number between 0 and 256') end end |
#verify(password, encrypted_password) ⇒ Object
15 16 17 |
# File 'lib/multi_password/strategies/scrypt.rb', line 15 def verify(password, encrypted_password) ::SCrypt::Password.new(encrypted_password) == password end |