Class: Ravelin::Password

Inherits:
RavelinObject show all
Defined in:
lib/ravelin/password.rb

Constant Summary collapse

FAILURE_REASONS =
%w(BAD_PASSWORD UNKNOWN_USERNAME INTERNAL_ERROR RATE_LIMIT)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RavelinObject

attr_accessor, attr_required, #initialize, required_attributes, #serializable_hash

Constructor Details

This class inherits a constructor from Ravelin::RavelinObject

Instance Attribute Details

#failure_reasonObject

Returns the value of attribute failure_reason.



5
6
7
# File 'lib/ravelin/password.rb', line 5

def failure_reason
  @failure_reason
end

#password_hashedObject

Returns the value of attribute password_hashed.



5
6
7
# File 'lib/ravelin/password.rb', line 5

def password_hashed
  @password_hashed
end

#successObject

Returns the value of attribute success.



5
6
7
# File 'lib/ravelin/password.rb', line 5

def success
  @success
end

Instance Method Details

#password=(passwd) ⇒ Object

Alternative interface, because when the attr is called “password_hashed”, the end user might think they need to hash the password themselves



10
11
12
# File 'lib/ravelin/password.rb', line 10

def password=(passwd)
  @password_hashed = Digest::SHA256.hexdigest(passwd)
end

#validateObject



20
21
22
23
24
25
# File 'lib/ravelin/password.rb', line 20

def validate
  super
  if !success && !FAILURE_REASONS.include?(failure_reason)
    raise ArgumentError.new("Failure reason value must be one of #{FAILURE_REASONS.join(', ')}")
  end
end