Sinatra, base rack and file search

using rack :: auth :: basic in sinatra application, there is a way so that I can search for users and password from a simple yaml file (it doesn’t matter if the password is saved in clear form)

Yaml config / users.yml example

--- :users: usersA: :password: passwordA :otherdata: xxxxx userB: :password: passwordB 

synatra configuration block that I am trying (without success). how can i search users from 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 
+4
source share
1 answer

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] 
+4
source

Source: https://habr.com/ru/post/1435242/


All Articles