Created
April 4, 2011 16:59
-
-
Save somebox/901979 to your computer and use it in GitHub Desktop.
Authenticate in Rails with super-simple HTTP Auth.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
users: | |
- name: foz | |
password: secret1 | |
- name: joe | |
password: secret2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
# 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