Could someone please explain for me what is happening here?
i feel like the documentation doesnt mention a lot or describe what is happening. it just say use this method like this.
what will happen if username and password are true, what will happen if false etc?
class AdminController < ApplicationController
USERNAME, PASSWORD = "humbaba", "5baa61e4"
before_filter :authenticate
private
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == USERNAME &&
Digest::SHA1.hexdigest(password) == PASSWORD
end
end
end
thanks
The
before_filtermethod ensures that the private methodauthenticateis run before all requests.authenticate_or_request_with_http_basicpops up the browser’s “enter your username and password” box, and passes them into the block, asusernameandpassword, in this case.If the block returns
true(if the username and password match), the request proceeds to your more specific code. If the block returnsfalse(the username and password don’t match), the request is cut short, and an authentication failure page with the correct HTTP status code is returned. The browser may retry the request a few more times before showing the failure page.