Module: Sinatra::SimpleAuthentication::Models::Common::InstanceMethods

Included in:
ActiveRecord::Adapter::InstanceMethods, DataMapper::Adapter::InstanceMethods
Defined in:
lib/sinatra/simple_authentication/models/common/instance_methods.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/sinatra/simple_authentication/models/common/instance_methods.rb', line 8

def password
  @password
end

#password_confirmationObject

Returns the value of attribute password_confirmation.



8
9
10
# File 'lib/sinatra/simple_authentication/models/common/instance_methods.rb', line 8

def password_confirmation
  @password_confirmation
end

Instance Method Details

#authenticate(pass) ⇒ Object



26
27
28
# File 'lib/sinatra/simple_authentication/models/common/instance_methods.rb', line 26

def authenticate(pass)
  encrypt(pass, self.salt) == self.hashed_password
end

#encrypt(password, salt) ⇒ Object



22
23
24
# File 'lib/sinatra/simple_authentication/models/common/instance_methods.rb', line 22

def encrypt(password, salt)
  Digest::SHA1.hexdigest(password + salt)
end

#generate_saltObject



18
19
20
# File 'lib/sinatra/simple_authentication/models/common/instance_methods.rb', line 18

def generate_salt
  (0..25).inject('') { |r, i| r << rand(93) + 33 }
end