Module: SimplePasswordAuthentication::ModelMethods::User

Defined in:
lib/simple_password_authentication/model_methods.rb

Defined Under Namespace

Modules: Behavior, ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



11
12
13
# File 'lib/simple_password_authentication/model_methods.rb', line 11

def password
  @password
end

Instance Method Details

#correct_password?(pw) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/simple_password_authentication/model_methods.rb', line 35

def correct_password?(pw)
  self.class.hash_password(pw, salt) == hashed_password
end

#hashed_password=(pw) ⇒ Object



27
28
29
# File 'lib/simple_password_authentication/model_methods.rb', line 27

def hashed_password=(pw)
  write_attribute(:hashed_password, self.class.hash_password(pw, salt))
end

#saltObject

Returns the salt value. If there is no value, one is generated.



14
15
16
17
18
# File 'lib/simple_password_authentication/model_methods.rb', line 14

def salt
  read_attribute(:salt) or returning self.class.generate_salt do |s|
    write_attribute(:salt, s)
  end
end

#salt!Object

Force re-generation of salt value. Returns new value.



21
22
23
24
25
# File 'lib/simple_password_authentication/model_methods.rb', line 21

def salt!
  returning self.class.generate_salt do |s|
    write_attribute(:salt, s)
  end
end