made a suggestion based on digininjas comment on Rails tutorials blog post. Better to change method name to hash_password than encrypt_password
This commit is contained in:
+2
-2
@@ -11,7 +11,7 @@ class User < ActiveRecord::Base
|
|||||||
validates_format_of :email, :with => /.+@.+\..+/i
|
validates_format_of :email, :with => /.+@.+\..+/i
|
||||||
attr_accessor :skip_user_id_assign
|
attr_accessor :skip_user_id_assign
|
||||||
before_save :assign_user_id, :on => :create
|
before_save :assign_user_id, :on => :create
|
||||||
before_save :encrypt_password
|
before_save :hash_password
|
||||||
has_one :retirement, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
|
has_one :retirement, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
|
||||||
has_one :paid_time_off, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
|
has_one :paid_time_off, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
|
||||||
has_one :work_info, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
|
has_one :work_info, :foreign_key => :user_id, :primary_key => :user_id, :dependent => :destroy
|
||||||
@@ -45,7 +45,7 @@ class User < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def encrypt_password
|
def hash_password
|
||||||
if self.password.present?
|
if self.password.present?
|
||||||
self.password = Digest::MD5.hexdigest(password)
|
self.password = Digest::MD5.hexdigest(password)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
Within app/models/user.rb:
|
Within app/models/user.rb:
|
||||||
</p>
|
</p>
|
||||||
<pre class="ruby">
|
<pre class="ruby">
|
||||||
before_save <span style="background-color:yellow">:encrypt_password</span>
|
before_save <span style="background-color:yellow">:hash_password</span>
|
||||||
|
|
||||||
def self.authenticate(email, password)
|
def self.authenticate(email, password)
|
||||||
auth = nil
|
auth = nil
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
return auth
|
return auth
|
||||||
end
|
end
|
||||||
|
|
||||||
def encrypt_password
|
def hash_password
|
||||||
if self.password.present?
|
if self.password.present?
|
||||||
self.password = <span style="background-color:yellow">Digest::MD5.hexdigest(password)</span>
|
self.password = <span style="background-color:yellow">Digest::MD5.hexdigest(password)</span>
|
||||||
end
|
end
|
||||||
@@ -98,7 +98,7 @@
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def encrypt_password
|
def hash_password
|
||||||
if self.password.present?
|
if self.password.present?
|
||||||
<span style="background-color:yellow">self.password_salt = BCrypt::Engine.generate_salt</span>
|
<span style="background-color:yellow">self.password_salt = BCrypt::Engine.generate_salt</span>
|
||||||
<span style="background-color:yellow">self.password_hash = BCrypt::Engine.hash_secret(self.password, self.password_salt)</span>
|
<span style="background-color:yellow">self.password_hash = BCrypt::Engine.hash_secret(self.password, self.password_salt)</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user