Class: User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

Virtual attribute for the unencrypted password



4
5
6
# File 'app/models/user.rb', line 4

def password
  @password
end

Class Method Details

.authenticate(login, password) ⇒ Object

Authenticates a user by their login name and unencrypted password. Returns the user or nil.



21
22
23
24
# File 'app/models/user.rb', line 21

def self.authenticate(, password)
  u = () # need to get the salt
  u && u.authenticated?(password) ? u : nil
end

.encrypt(password, salt) ⇒ Object

Encrypts some data with the salt.



27
28
29
# File 'app/models/user.rb', line 27

def self.encrypt(password, salt)
  Digest::SHA1.hexdigest("--#{salt}--#{password}--")
end

Instance Method Details

#authenticated?(password) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/user.rb', line 36

def authenticated?(password)
  crypted_password == encrypt(password)
end

#encrypt(password) ⇒ Object

Encrypts the password with the user salt



32
33
34
# File 'app/models/user.rb', line 32

def encrypt(password)
  self.class.encrypt(password, salt)
end