Class: Singularity::PasswordHash
- Inherits:
-
Object
- Object
- Singularity::PasswordHash
- Defined in:
- lib/singularity/password_hash.rb
Instance Attribute Summary collapse
-
#digest ⇒ Object
readonly
Returns the value of attribute digest.
Class Method Summary collapse
- .digest_algorithm ⇒ Object
- .generate(password, salt) ⇒ Object
- .iterations ⇒ Object
- .key_length ⇒ Object
Instance Method Summary collapse
-
#initialize(digest = nil) ⇒ PasswordHash
constructor
A new instance of PasswordHash.
- #matches?(password, salt) ⇒ Boolean
Constructor Details
#initialize(digest = nil) ⇒ PasswordHash
Returns a new instance of PasswordHash.
8 9 10 |
# File 'lib/singularity/password_hash.rb', line 8 def initialize(digest = nil) @digest = digest end |
Instance Attribute Details
#digest ⇒ Object (readonly)
Returns the value of attribute digest.
6 7 8 |
# File 'lib/singularity/password_hash.rb', line 6 def digest @digest end |
Class Method Details
.digest_algorithm ⇒ Object
14 15 16 |
# File 'lib/singularity/password_hash.rb', line 14 def self.digest_algorithm OpenSSL::Digest::SHA512.new end |
.generate(password, salt) ⇒ Object
22 23 24 |
# File 'lib/singularity/password_hash.rb', line 22 def self.generate(password, salt) OpenSSL::PKCS5.pbkdf2_hmac(password, salt, iterations, key_length, digest_algorithm).unpack('H*').first end |
.iterations ⇒ Object
12 |
# File 'lib/singularity/password_hash.rb', line 12 def self.iterations; 20_000; end |
.key_length ⇒ Object
18 19 20 |
# File 'lib/singularity/password_hash.rb', line 18 def self.key_length digest_algorithm.length end |
Instance Method Details
#matches?(password, salt) ⇒ Boolean
26 27 28 |
# File 'lib/singularity/password_hash.rb', line 26 def matches?(password, salt) Rack::Utils.secure_compare digest, self.class.generate(password, salt) end |