Re: htpasswd question

From: Jason Tonkin <[email protected]>
Date: Tue, 07 Mar 2000 14:41:11 +1300

Hi Jim,

I had the same problem, this little custom perl script may help you,
You will need to modify the paths to suit your system, it may seem
rather long winded but thats half the fun!!

The txt file feeding the script must be in the following format;
username<space>password<space>
Everything after the second blank space gets chomped, it doesnt use
htpasswd either, it uses the perl crypt function.

Let me know how you get on!

regards
 
Jason Tonkin
Unix Systems Administrator
Land Information New Zealand
http://www.linz.govt.nz [email protected]
Phone (04)4600174 (025)811382 Fax (04)4600166

#!/usr/bin/perl

#
--------------------------------------------------------------------------
# Create a passwd file for Squid (htpasswd) using a plaintext input file
# Created on 1999/03/15
#
--------------------------------------------------------------------------

#
--------------------------------------------------------------------------
# assign some useful vars

$squid_plaintext_file = 'proxyid.txt';
$squid_passwd_file = 'passwd';
$tmp_squid_passwd_file = 'passwd.tmp';

# create a random salt
@range=('0'..'9','a'..'z','A'..'Z');
srand($$|time);
$salt=$range[rand(int($#range)+1)] . $range[rand(int($#range)+1)];
#
--------------------------------------------------------------------------
open (squid_plaintext_file,"$squid_plaintext_file") || die "Can't open
$squid_plaintext_file: $!\n";
open (squid_passwd_file,">$tmp_squid_passwd_file") || die "Can't open
$squid_passwd_file: $!\n";
while (<squid_plaintext_file>){
        chomp;
        $count += 1;
        ($user_name,$plaintext_passwd) = split;
        $crypt_passwd = crypt($plaintext_passwd, "$salt");
        print squid_passwd_file "$user_name:$crypt_passwd\n";
}
close squid_plaintext_file;
close squid_passwd_file;

if ( $count > 150 ){
        rename $tmp_squid_passwd_file, $squid_passwd_file;
        chmod 0644, $squid_passwd_file;

Jim Chivas wrote:
>
> Greetings:
>
> I am trying to make the 'htpasswd' program read a list of ids and
> passwords from a file. I have tried several different ways:
>
> 1. htpasswd -b passwdfile < test file
>
> 2. read file for id passwd
>
> htpasswd -b passwdfile $id $passwd
>
> done
>
> 3. cat file | htpasswd -b passwdfile
>
> The above syntax is not exactly correct but should give you an idea of
> what I tried.
>
> Is it possible to get 'htpasswd' to read from a file?
>
> Thanks
>
> Jim
>
> -- ---------------------------------------------------------------------
>
> Jim Chivas, Computing/Network Services email: jchivas@langara.bc.ca
> Langara College fax: (604) 323-5349
> 100 West 49th Avenue Voice: (604) 323-5390
> Vancouver, B.C., Canada http://www.langara.bc.ca
> V5Y 2Z6
Received on Mon Mar 06 2000 - 18:43:56 MST

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:51:56 MST