Class: Ravelin::Password

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

Constant Summary collapse

FAILURE_REASONS =
%w(BAD_PASSWORD UNKNOWN_USERNAME AUTHENTICATION_FAILURE INTERNAL_ERROR RATE_LIMIT BANNED_USER)

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

#emailPasswordSHA256Object

Returns the value of attribute emailPasswordSHA256.



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

def emailPasswordSHA256
  @emailPasswordSHA256
end

#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

#passwordSHA1SHA256Object

Returns the value of attribute passwordSHA1SHA256.



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

def passwordSHA1SHA256
  @passwordSHA1SHA256
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

#emailPassword=(emailPassword) ⇒ Object



19
20
21
# File 'lib/ravelin/password.rb', line 19

def emailPassword=(emailPassword)
  @emailPasswordSHA256 = Digest::SHA256.hexdigest(emailPassword)
end

#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
13
# File 'lib/ravelin/password.rb', line 10

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

#validateObject



29
30
31
32
33
34
# File 'lib/ravelin/password.rb', line 29

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