You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Doug MacEachern <do...@opengroup.org> on 1997/07/22 14:27:35 UTC

Re: one for the FAQ

[...]
> +  <LI><A NAME="htpasswd-how">
> +       <STRONG>How do I make htpasswd/dbm/gdb/msql password entries?</STRONG>
> +      </A>
> +   <P>
> +   The various authenfication modules, such as mod_auth, mod_auth_gdb, 
> + mod_auth_dbm, mod_auth_msql and quite a few contributed modules with
> + oracle, postgress and sybase connections rely on a <emp>crypted</emp> 
> + password field. This is a one-way crypt, as are the entries in your
> + normal passwd file on most unix systems. One needs a tool or a bit of
> + perl to create these entries.</p>
> +   <p>
> +   In the <samp>support</samp> directory of the source distribution you
> + will find (or can compile) a binary 'htpasswd' which is a simple 
> + password file management tool which will create those crypted entries.</p>
> +   <p>
> +   Another option is to use the bit of perl below;
> + <blockquote><code><pre>
> + #!/usr/local/bin/perl
> + # Export 0/0a dirkx@technologist.com - Tue Jul 22 08:12:48 GMT 1997
> + #
> + if ($#ARGV != -1) {
> + 	print STDERR "usage: $0 (stdin/out only)\n";
> + 	exit -1;
> + 	};
> + 
> + while(<STDIN>) {
> + 	chomp;
> + 	print crypt_passwd($_)."\n";
> + 	};
> + exit 0;
> + 
> + sub to64 {
> +         local ($v,$n)=@_; local $s,$a;
> +         $a="./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
> +         while (--$n >=0 ) {
> +                 $s.=substr($a,($v % 64),1);
> +                 $v>>=6;
> +                 };
> +         return $s;
> +         };
> +  
> + sub crypt_passwd {
> +         local ($passwd,$salt)=@_;
> +         if (!($salt)) {
> +                 srand(time);
> +                 $salt=to64(rand(64*64),2);
> +                 };
> +         return crypt($passwd,$salt);
> +         };

Some might like to know about: 
http://www.perl.com/CPAN/modules/by-module/HTTPD-Tools-x.xx.tar.gz

This'll add a crypt'd password to an mSQL database:

    my $u = HTTPD::UserAdmin->new(
            DBType =>    "SQL",
            Host =>      "",             #server hostname
            DB =>        "www",          #database name
            User =>      "",             #database login name
            Auth =>      "",             #database login password
            Driver =>    "mSQL",         #driver for DBI required
            UserTable => "www-users",    #table with field names below
            NameField => "user",         #field for the name
            PasswordField => "password", #field for the password
            );

       $u->add($username,$password); 

`Driver' could also be, Mysql, Pg, Oracle, Sybase, Informix, etc.

While I'm at it, mod_auth_*db*:

    my $u = HTTPD::UserAdmin->new(
            DBType => 'DBM',
            Server => 'apache',
            DB     => '.htpasswd',
            #DBMF  => 'DB', #default is NDBM, can be `DB' (Berkley), GDBM, etc.            );

mod_digest:

    my $u = HTTPD::UserAdmin->new(
            Encrypt => 'MD5',
            DBType  => 'Text', #or DBM
            Server => 'apache',
            DB     => '.htdigest',
            );

There's also HTTPD::GroupAdmin and some other goodies in there.

-Doug