Deprecated class. This class is not used and will be removed soon.
Methods
Attributes
| [RW] | password | Virtual attribute for the unencrypted password |
Public Class methods
Authenticates a user by their login name and unencrypted password. Returns the user or nil.
[ show source ]
# File app/models/user.rb, line 20
20: def self.authenticate(login, password)
21: u = find_by_login(login) # need to get the salt
22: u && u.authenticated?(password) ? u : nil
23: end
Encrypts some data with the salt.
[ show source ]
# File app/models/user.rb, line 26
26: def self.encrypt(password, salt)
27: pepper = '66ee62b3951b7f2c9494d9c3787ae765a2f9fe4214b0fef5b214010c3441b738'
28: Digest::SHA256.hexdigest("--#{salt}--#{password}--#{pepper}--")
29: end
Public Instance methods
[ show source ]
# File app/models/user.rb, line 36
36: def authenticated?(password)
37: crypted_password == encrypt(password)
38: end
Encrypts the password with the user salt
[ show source ]
# File app/models/user.rb, line 32
32: def encrypt(password)
33: self.class.encrypt(password, salt)
34: end
Protected Instance methods
before filter
[ show source ]
# File app/models/user.rb, line 42
42: def encrypt_password
43: return if password.blank?
44: self.salt = Digest::SHA256.hexdigest("--#{Time.now.to_s}--#{login}--") if new_record?
45: self.crypted_password = encrypt(password)
46: end
[ show source ]
# File app/models/user.rb, line 48
48: def password_required?
49: crypted_password.blank? || !password.blank?
50: end