sinatra, rack auth basic and lookup from file
rack, ruby, sinatra
Solution
Simple as:
configure do
config = YAML::load_file(File.join(Dir.pwd, 'config', 'users.yml'))
use Rack::Auth::Basic, "login" do |u, p|
p == config[:users][u][:password]
end
end
You may also consider storing passwords as SHA1 and checking as:
Digest::SHA1.hexdigest(p) == config[:users][u][:password]
Problem
using rack::auth::basic in a sinatra application, there is a way that i can lookup users and password from simple yaml file (doesn't matter if password is kept in clear)? example yaml config/users.yml ``` --- :users: usersA: :password: passwordA :otherdata: xxxxx userB: :password: passwordB ``` the sinatra configure block i'm trying (with no success). how i can lookup the users from the yaml file? ``` configure do config = YAML::load_file(File.join(Dir.pwd, 'config', 'users.yml')) use Rack::Auth::Basic, "login" do |u, p| [u, p] == [u, config[:users][username][:password]] end end ```