Mastering Nginx

(Ron) #1
Chapter 6

[ 135 ]

puts o; exit


end


end


initialize an array of ASCII characters to be used for the salt


ascii = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a + [ ".",
"/" ]


$lines = []


begin


read in the current http auth file


File.open($file) do |f|


f.lines.each { |l| $lines << l }


end


rescue Errno::ENOENT


if the file doesn't exist (first use), initialize the array


$lines = ["#{$user}:#{$pass}\n"]


end


remove the user from the current list, since this is the one we're


editing
$lines.map! do |line|


unless line =~ /#{$user}:/


line


end


end


generate a crypt()ed password


pass = $pass.crypt(ascii[rand(64)] + ascii[rand(64)])

Free download pdf