Skip to content

Instantly share code, notes, and snippets.

@boblmartens
Created November 25, 2008 01:31
Show Gist options
  • Save boblmartens/28740 to your computer and use it in GitHub Desktop.
Save boblmartens/28740 to your computer and use it in GitHub Desktop.
a possible password system
attr_accessor :new_password
validates_presence_of :new_password, :on => :create
validates_length_of :new_password, :minimum => 6, :allow_nil => true, :allow_blank => true, :unless => :new_password.blank?
validates_confirmation_of :new_password
before_save :set_encrypted_password
def set_encrypted_password
write_attribute(:password, Client.encrypt_password(@new_password)) unless @new_password.nil? || @new_password.blank?
end
def self.encrypt_password(password)
Digest::SHA1.hexdigest("something_random_goes_here_#{password}")
end
def self.authenticate(email, password)
find_by_email_and_password_and_active(email, encrypt_password(password), true)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment