Class: SCrypt::Password
- Inherits:
-
String
- Object
- String
- SCrypt::Password
- Defined in:
- lib/scrypt-ruby.rb
Instance Attribute Summary collapse
-
#cost ⇒ Object
readonly
Returns the value of attribute cost.
-
#digest ⇒ Object
readonly
Returns the value of attribute digest.
-
#salt ⇒ Object
readonly
Returns the value of attribute salt.
Class Method Summary collapse
Instance Method Summary collapse
- #==(plaintext_password) ⇒ Object (also: #is_password?)
-
#initialize(encrypted_password) ⇒ Password
constructor
A new instance of Password.
Constructor Details
#initialize(encrypted_password) ⇒ Password
Returns a new instance of Password.
26 27 28 29 30 |
# File 'lib/scrypt-ruby.rb', line 26 def initialize(encrypted_password) encrypted_password = encrypted_password.to_s raise Errors::InvalidHash, "invalid hash" unless valid_hash? encrypted_password @cost, @salt, @digest = split_hash(replace(encrypted_password)) end |
Instance Attribute Details
#cost ⇒ Object (readonly)
Returns the value of attribute cost.
24 25 26 |
# File 'lib/scrypt-ruby.rb', line 24 def cost @cost end |
#digest ⇒ Object (readonly)
Returns the value of attribute digest.
24 25 26 |
# File 'lib/scrypt-ruby.rb', line 24 def digest @digest end |
#salt ⇒ Object (readonly)
Returns the value of attribute salt.
24 25 26 |
# File 'lib/scrypt-ruby.rb', line 24 def salt @salt end |
Class Method Details
.create(plaintext_password, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/scrypt-ruby.rb', line 32 def self.create(plaintext_password, = {}) = Engine::DEFAULTS.merge() key_len = [[.delete(:key_len), 16].max, 512].min [:salt_size] = [[[:salt_size], 8].max, 32].min salt = Engine.generate_salt() hash = Engine.hash_secret(plaintext_password, salt, key_len) new(hash) end |
Instance Method Details
#==(plaintext_password) ⇒ Object Also known as: is_password?
41 42 43 |
# File 'lib/scrypt-ruby.rb', line 41 def ==(plaintext_password) self.class.secure_compare(self, Engine.hash_secret(plaintext_password, @cost + @salt, self.digest.length / 2)) end |