Htpasswd

How to generate apache password with ruby? I have to generate from ruby
code the same password like htpasswd2 -m make. In other words: from ruby
on rails application I have to generate a password, which will be used
not only for login, but also to generate apache config files (e.g.
password files for subversion) - so the password must be exactly the
same.
Can someone help me?
Sorry for my english…

On Thu, May 22, 2008 at 07:51:39AM +0900, Anka Anka wrote:

How to generate apache password with ruby? I have to generate from ruby
code the same password like htpasswd2 -m make. In other words: from ruby
on rails application I have to generate a password, which will be used
not only for login, but also to generate apache config files (e.g.
password files for subversion) - so the password must be exactly the
same.
Can someone help me?
Sorry for my english…

Try out the htauth gem and see if it works for you:

gem install htauth

http://copiousfreetime.rubyforge.org/htauth/

HTAuth is a pure ruby replacement for the Apache support programs
htdigest
and htpasswd. Command line and API access are provided for access
and
control of htdigest and htpasswd files.

enjoy,

-jeremy

On May 21, 2008, at 4:51 PM, Anka Anka wrote:

How to generate apache password with ruby? I have to generate from
ruby
code the same password like htpasswd2 -m make. In other words: from
ruby
on rails application I have to generate a password, which will be used
not only for login, but also to generate apache config files (e.g.
password files for subversion) - so the password must be exactly the
same.
Can someone help me?
Sorry for my english…

the webrick library, which is included with ruby, has tools for
generating and manipulating htpasswd files - the docs are slim but the
code is quite easy to read

start with

webrick/httpauth/htpasswd.rb

cheers.

a @ http://codeforpeople.com/

On Thu, May 22, 2008 at 07:16:24PM +0900, Anka Anka wrote:

Thanks. It works

Glad to help out, let me know if you find any bugs.

enjoy,

-jeremy

Thanks. It works

Needed to know this so found out what to run from Webrick:

require ‘webrick/httpauth/basicauth’
WEBrick::HTTPAuth::UserDB::BasicAuth::make_passwd(‘realm’, ‘user’,
‘pass’)
-> “uVYUjG9q8pg8o”

Thanks to Ara for the pointer.

In fact, looking at webrick/httpauth/basicauth.rb it seems all you need
is to use crypt.

require 'webrick/utils'
crypted_pass.crypt(WEBrick::Utils.random_string(2))

I have not yet tested this though.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs