Skip to content

Instantly share code, notes, and snippets.

@somebox
Created April 4, 2011 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save somebox/901979 to your computer and use it in GitHub Desktop.
Save somebox/901979 to your computer and use it in GitHub Desktop.
Authenticate in Rails with super-simple HTTP Auth.
users:
- name: foz
password: secret1
- name: joe
password: secret2
class Admin::BaseController < ApplicationController
before_filter :authenticate
# ...
private
def authenticate
return true if Rails.env.development?
authenticate_or_request_with_http_basic do |id, password|
ADMIN_USERS["users"].each do |user|
# for better security, use SHA1 or something for password!
return true if (id == user["name"] and password == user["password"])
end
return false
end
end
end
# ...
# load admin users
ADMIN_USERS = YAML::load_file('config/admin.yml')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment