Sha256: adcaef422bb669e9a7d0091f34f0571f7e05a6cd5504e31a0009db5edcc7a722

Contents?: true

Size: 784 Bytes

Versions: 6

Compression:

Stored size: 784 Bytes

Contents

  attr_accessor :password
  before_save :encrypt_password

  validates_presence_of :email
  validates_uniqueness_of :email
  validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
  validates_presence_of :password, :on => :create
  validates_confirmation_of :password
  validates_length_of :password, :minimum => 4 

  def self.authenticate(email, password)
    user = find(:first, :conditions => {:email => email})
    if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
      user
    else
      nil
    end
  end

  def encrypt_password
    if password.present?
      self.password_salt = BCrypt::Engine.generate_salt
      self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
    end
  end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
i0n_rails3_generators-0.2.19 lib/generators/i0n/authentication/templates/app/models/_user.rb
i0n_rails3_generators-0.2.18 lib/generators/i0n/authentication/templates/app/models/_user.rb
i0n_rails3_generators-0.2.17 lib/generators/i0n/authentication/templates/app/models/_user.rb
i0n_rails3_generators-0.2.16 lib/generators/i0n/authentication/templates/app/models/_user.rb
i0n_rails3_generators-0.2.15 lib/generators/i0n/authentication/templates/app/models/_user.rb
i0n_rails3_generators-0.2.14 lib/generators/i0n/authentication/templates/app/models/_user.rb