Guest User

Untitled

a guest
Apr 8th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. Application_user = Settings[:authentication][:user]
  2. Application_pass = Settings[:authentication][:password]
  3.  
  4. def protected! username = Application_user, password = Application_pass
  5. unless authorized? username, password
  6. response['WWW-Authenticate'] = %(Basic realm="Testing HTTP Auth")
  7. throw(:halt, [401, "Not authorized\n"])
  8. end
  9. end
  10.  
  11. def authorized? username, password
  12. username = Settings
  13. @auth ||= Rack::Auth::Basic::Request.new(request.env)
  14. @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == [username, password]
  15. end
Add Comment
Please, Sign In to add comment