2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/hobo_devise/database_authenticable.rb', line 2
def self.database_authenticable(model)
model.class_eval do
devise :database_authenticatable
fields do
crypted_password :string, :limit => 60
end
def password=(new_password)
@password = new_password
self.encrypted_password = password_digest(@password) if @password.present?
end
def crypted_password; end
def crypted_password=(n); end
def validate_current_password_when_changing_password; end
def password_salt; salt; end
def password_salt=(n); salt=n; end
def encrypted_password; read_attribute(:crypted_password); end
def encrypted_password=(n); write_attribute(:crypted_password, n); end
require 'bcrypt'
def password_digest(password)
::BCrypt::Password.create("#{password}#{self.class.pepper}", :cost => self.class.stretches).to_s
end
def valid_password?(password)
bcrypt = ::BCrypt::Password.new(self.encrypted_password)
password = ::BCrypt::Engine.hash_secret("#{password}#{self.class.pepper}", bcrypt.salt)
Devise.secure_compare(password, self.encrypted_password)
end
def authenticated?(password)
self.valid_password?(password)
end
end
end
|