1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
## publisher_controller.rb
class Admin::PublisherController < ApplicationController
  def login
    return unless request.post?
    publisher = Publisher.find_by_name(params[:publisher][:name])
    if publisher.password == params[:publisher][:password]
      redirect_to :action => 'index'
    else
      flash.now[:notice] = "Please login!"
    end
  end
end

## Publisher.rb
# == Schema Information
# Schema version: 9
#
# Table name: publishers
#
#  id       :integer(11)   not null, primary key
#  name     :string(255)   default(""), not null
#  email    :string(255)   
#  secret   :string(255)   
#

# Require BCrypt library.
require 'bcrypt'

class Publisher < ActiveRecord::Base
  include BCrypt
  
  def password
    @password ||= Password.new(secret)
  end
  
  def password=(new_password)
    @password = Password.create(new_password)
    self.secret = @password
  end
end