Class: ROM::Auth::PasswordVerifiers::PasswordVerifier
- Inherits:
-
Object
- Object
- ROM::Auth::PasswordVerifiers::PasswordVerifier
- Defined in:
- lib/rom/auth/password_verifiers/password_verifier.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :iterations => 15000, :hash_function => :sha256 }.freeze
- DEFAULT_SALT_LENGTH =
16
- SEPARATOR =
","
- VERIFIERS =
{}
Instance Attribute Summary collapse
-
#digest ⇒ Object
readonly
Returns the value of attribute digest.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#salt ⇒ Object
readonly
Returns the value of attribute salt.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#digest ⇒ Object (readonly)
Returns the value of attribute digest.
11 12 13 |
# File 'lib/rom/auth/password_verifiers/password_verifier.rb', line 11 def digest @digest end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/rom/auth/password_verifiers/password_verifier.rb', line 11 def @options end |
#salt ⇒ Object (readonly)
Returns the value of attribute salt.
11 12 13 |
# File 'lib/rom/auth/password_verifiers/password_verifier.rb', line 11 def salt @salt end |
Class Method Details
.for_password(plaintext_password, options = {}) ⇒ Object
31 32 33 34 |
# File 'lib/rom/auth/password_verifiers/password_verifier.rb', line 31 def self.for_password(plaintext_password, ={}) raise ArgumentError unless plaintext_password.is_a?(String) new(.merge(:password => plaintext_password)) end |
.from_s(string) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/rom/auth/password_verifiers/password_verifier.rb', line 36 def self.from_s(string) kind, salt, digest, iterations = string.split(SEPARATOR) raise(ArgumentError, "Invalid password verifier kind: #{kind.inspect}") unless VERIFIERS.keys.map(&:to_s).include?(kind) VERIFIERS[kind.to_sym].new(DEFAULT_OPTIONS.merge(:digest => digest, :salt => salt, :iterations => iterations.to_i)) end |
Instance Method Details
#==(other) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/rom/auth/password_verifiers/password_verifier.rb', line 23 def ==(other) case other when PasswordVerifier then to_s == other.to_s when String then to_s == other else false end end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/rom/auth/password_verifiers/password_verifier.rb', line 19 def to_s [type, salt, digest.to_s, [:iterations]].join(SEPARATOR) end |
#verifies?(plaintext_password) ⇒ Boolean
13 14 15 16 17 |
# File 'lib/rom/auth/password_verifiers/password_verifier.rb', line 13 def verifies?(plaintext_password) tested_digest = compute_digest(plaintext_password, salt, ) digest == tested_digest end |