require 'digest/sha1' class UnstaticPassword < ActiveRecord::Base def self.encrypt(string) Digest::SHA1.hexdigest(string) end def self.authorized?(password) UnstaticPassword.find_by_encrypted(encrypt(password)) ? true : false end def password=(string) self.encrypted = UnstaticPassword.encrypt(string) end end