What is the best way to password protect a view? I already am generating a password but I don't want a username and password login, just the password. I have the password being stored currently as a attribute in the File class, and was using this:
before_filter :restrict, :only => :show
authenticate_or_request_with_http_basic do |password|
password == @file.password
end
However, it still prompts the user for a username and doesn't log in correctly because it is missing a username. Is there a way to use this method and only have the prompt ask for the password only? If not what is the best way to go about doing this?
authenticate_or_request_with_http_basic is implemented using HTTP Basic Auth that requires combination of username and password to be entered. If you want to enable password only authentication, you will have to write your own authentication method
before_filter :restrict, :only=>:show
def restrict(password)
render :status=>401, :text=>"Unathorized" unless password == @file.password
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With