Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

password files in apache problem

Status
Not open for further replies.

wieglenda

IS-IT--Management
Feb 8, 2003
30
US
I recently moved from apache 2.0.44 for windows to 2.0.42 for linux and I'm trying to move my .htaccess AuthUserFile over to linux. The AuthUserFile is simple text with no encrypted passwords, the format looks like this:

User:pass
Dog:cat
chicken:horse

I moved the password file to my linux box and changed the httpd.conf file to protect a members area using that password file. The problem is, linux apache automatically encrypts the password that you input, so when it compares the inputted password to the password file, there is no match. Now this password file is about 3000 line long, so converting one password at a time will take forever. Does anyone know how to: A. Disable encryption on apache, B. Use a program to convert a batch of passwords into standard unix crypt format?

Thanks a ton to whoever can respond

Thomas
 
A is only doable on Windows platforms.

B shouldn't be too hard. This PERL script should do it:
[tt]#!/usr/bin/perl

my $FILE, $HTPASSWD, @content, $username, $password;

$FILE="/path/to/file"
$HTPASSWD="/path/to/apache/bin/htpaswd"

open(PASSWD, &quot;< $FILE&quot;) or die(&quot;Unable to open $FILE&quot;);
@content = <PASSWD>;
close(PASSWD);

foreach my $line (@content)
{
($username, $password) = split(&quot;:&quot;, $line);
exec(&quot;$HTPASSWD -b $FILE $username $password&quot;);
}[/tt]

Note that my PERL is somewhat rusty, so if it doesn't work, please post back with the error you get. //Daniel
 
Ok, to tell you the truth I really don't know much about Perl, but I did type the script in (after running the perl command out of /etc/bin folder) and I don't know how to execute it.

my $FILE, $HTPASSWD, @content, $username, $password, $line;
$FILE=&quot;etc/httpd/conf/word&quot;;
$HTPASSWD=&quot;usr/bin/htpasswd&quot;;
open(PASSWD, &quot;< $FILE&quot;) or die(&quot;Unable to open $FILE&quot;);
@content=<PASSWD>;
close(PASSWD);
foreach my $line (@content)
{ ($username, $password) = split(&quot;:&quot;, $line);
exec(&quot;$HTPASSWD -b $FILE $username $password&quot;);
}

This is the final code that I typed in. I made a few minor changes after receiving a couple of syntax errors, but now I don't know how to launch it :)

Thomas
 
Ok, hehe, I got the script to run, but it only does one password. How can I make it loop back to do all 3000 passwords?

BTW, thanks for the help sofar :)

Thomas
 
I tried this script, and it works fine on my system:
[tt]#!/usr/bin/perl

my ($passwdfile, $HTPASSWD, @content, $username, $password);

$passwdfile = &quot;/file/with/passwords&quot;;
$HTPASSWD = &quot;/path/to/apache/bin/htpasswd&quot;;

open(PASSWD, &quot;< $passwdfile&quot;) or die(&quot;Unable to open $passwdfile&quot;);
@content = <PASSWD>;
close(PASSWD);

foreach my $line (@content)
{
($username, $password) = split(&quot;:&quot;, $line);
print `$HTPASSWD -b $passwdfile $username $password`;
}[/tt] //Daniel
 
Yes, I got it to work also, but like I said, how do you cause it to loopback over and over for each line and change all of the passwords?

Thomas
 
This successfully changes all passwords in my test files.
How are you running it? //Daniel
 
woohoo, works like a champ after I read a few lines about running perlscript...

Thanks for all the help :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top