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.
7 8 9 |
# File 'lib/singularity/password_hash.rb', line 7 def initialize(digest = nil) @digest = digest end |
Instance Attribute Details
#digest ⇒ Object (readonly)
Returns the value of attribute digest.
5 6 7 |
# File 'lib/singularity/password_hash.rb', line 5 def digest @digest end |
Class Method Details
.digest_algorithm ⇒ Object
13 14 15 |
# File 'lib/singularity/password_hash.rb', line 13 def self.digest_algorithm OpenSSL::Digest::SHA512.new end |
.generate(password, salt) ⇒ Object
21 22 23 |
# File 'lib/singularity/password_hash.rb', line 21 def self.generate(password, salt) OpenSSL::PKCS5.pbkdf2_hmac(password, salt, iterations, key_length, digest_algorithm).unpack('H*').first end |
.iterations ⇒ Object
11 |
# File 'lib/singularity/password_hash.rb', line 11 def self.iterations; 20_000; end |
.key_length ⇒ Object
17 18 19 |
# File 'lib/singularity/password_hash.rb', line 17 def self.key_length digest_algorithm.length end |
Instance Method Details
#matches?(password, salt) ⇒ Boolean
25 26 27 |
# File 'lib/singularity/password_hash.rb', line 25 def matches?(password, salt) Rack::Utils.secure_compare digest, self.class.generate(password, salt) end |