Skip to content

Commit

Permalink
encrypting user password whenever password exists and user is saved s…
Browse files Browse the repository at this point in the history
…o it works on user edit - closes ryanb#2
  • Loading branch information
ryanb committed May 5, 2009
1 parent de06e99 commit 7b5f755
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions rails_generators/nifty_authentication/templates/user.rb
Expand Up @@ -3,7 +3,7 @@ class <%= user_class_name %> < ActiveRecord::Base
attr_accessible :username, :email, :password, :password_confirmation
attr_accessor :password
before_create :prepare_password
before_save :prepare_password
validates_presence_of :username
validates_uniqueness_of :username, :email, :allow_blank => true
Expand All @@ -26,8 +26,10 @@ def matching_password?(pass)
private

def prepare_password
self.password_salt = Digest::SHA1.hexdigest([Time.now, rand].join)
self.password_hash = encrypt_password(password)
unless password.blank?
self.password_salt = Digest::SHA1.hexdigest([Time.now, rand].join)
self.password_hash = encrypt_password(password)
end
end

def encrypt_password(pass)
Expand Down

0 comments on commit 7b5f755

Please sign in to comment.