Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Defined in:
- app/models/user.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Virtual attribute for the unencrypted password.
Class Method Summary collapse
-
.authenticate(login, password) ⇒ Object
Authenticates a user by their login name and unencrypted password.
-
.encrypt(password, salt) ⇒ Object
Encrypts some data with the salt.
Instance Method Summary collapse
- #authenticated?(password) ⇒ Boolean
-
#encrypt(password) ⇒ Object
Encrypts the password with the user salt.
Instance Attribute Details
#password ⇒ Object
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(login, password) u = find_by_login(login) # 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
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 |