23

和有什么区别

http_basic_authenticate_with()

authenticate_or_request_with_http_basic()

方法?

感谢您的完整解释。

4

1 回答 1

27

据我从文档中了解到的,http_basic_authenticate_with充当一个接受名称和密码的前置过滤器,例如

http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index

而 authenticate_or_request_with_http_basic 接受一个块,允许您插入一些代码以确定是否应该对其进行身份验证(文档)。例如

before_filter :authenticate

def authenticate
  authenticate_or_request_with_http_basic('Administration') do |username, password|
    ActiveSupport::SecurityUtils.secure_compare(username, "admin") &&
    ActiveSupport::SecurityUtils.secure_compare(password, "password")
  end
end
于 2013-03-27T15:53:33.227 回答