Attributy: id="htauth"
Odkazy:
Knihovna HTAuth realizuje v Ruby všechny operace s hesly a jejich hashi jako původní programy od Apache htdigest a htpasswd.
Knihovna je dostupná jako gem balíček a její instalace je tedy velmi snadná.
#gem install htauthSuccessfully installed htauth-1.0.3
Příklad 37.1. Ukázka získání apr1 hashe hesla, apr1.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'htauth'
heslo = ARGV[0]
apr1=HTAuth::Md5.new.encode(heslo)
puts "heslo=#{heslo}"
puts "apr1=#{apr1}"$./apr1.rb hesloheslo=heslo apr1=$apr1$t69wKyx3$Ci1IiXyBjnMrK1Ibc1G5C1
Příklad 37.2. Získání apr1 hashe hesla
# File: session/apr1.sesrequire 'rubygems'truerequire 'htauth'trueapr1 = HTAuth::Md5.new.encode('heslo')"$apr1$Gv1AJL8q$0HU08QWAjdaq/sXjARpKn/"
Příklad 37.3. Kontrola hesla
# File: session/htauth.authenticate.sesrequire 'rubygems'truerequire 'htauth'trueline = 'radek:$apr1$SsPBHx9k$Yk5CifOFhRqKBRySquO3P1'"radek:$apr1$SsPBHx9k$Yk5CifOFhRqKBRySquO3P1"entry = HTAuth::PasswdEntry.from_line(line)#<HTAuth::PasswdEntry:0x7f2abffb9e60 @algorithm=#<HTAuth::Md5:0x7f2abffb96b8 @salt="SsPBHx9k">, @user="radek", @digest="$apr1$SsPBHx9k$Yk5CifOFhRqKBRySquO3P1">entry.authenticated?('heslo')true
