.htpasswd problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jchibbra
Forum Newbie
Posts: 11
Joined: Wed Apr 30, 2003 5:48 pm

.htpasswd problem

Post by jchibbra »

Hi,

I have the following problem with my .htpasswd.
when I use the htpasswd program it works fine. I can protect my directory.
when I use php and the following code to create the .htpasswd I have an authentication failure. I guess the .htpasswd hasn't been created fine.

code:
------
$log="toto";
$pass="toto42";
$htpasswd_txt .= "$log:".crypt($pass,CRYPT_STD_DES)."\n";
$htpasswd = fopen(".htpasswd", "w");
$r = fputs($htpasswd, $htpasswd_txt);
fclose($htpasswd);

so when I have the popup for login/passwd I put toto and toto42 and I cannot access the directory.
And the log told me that it is an authentication failure:

user toto: authentication failure for "/path/to/the/file/index.htm": password mismatch

Is someone know why?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

can you build an example password via htpasswd and post it here?
jchibbra
Forum Newbie
Posts: 11
Joined: Wed Apr 30, 2003 5:48 pm

Post by jchibbra »

.htaccess:
------------

AuthUserFile "/var/www/vhost1/https/.htpasswd"
AuthName UserAuthentication
AuthType Basic
require valid-user

its path is: "/var/www/vhost1/http/galleries/rep1/.htpasswd"

and of course my .htpasswd is in :"/var/www/vhost1/https/"
the thing I don't understand is why with "htpasswd" it works and just after I use my function to create the .htpasswd and it doesn't work?

let me know if you need more information
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I meant an actual password, so we can see which algorithm has been used ;)
jchibbra
Forum Newbie
Posts: 11
Joined: Wed Apr 30, 2003 5:48 pm

Post by jchibbra »

Sorry :-)

for the example I took toto/toto42 as login/pass.
With htpasswd function the .htaccess looks like:
toto:2qm.tGvVQqiJY

when I use the my php function which is:
$log="toto";
$pass="toto42";
$htpasswd_txt .= "$log:".crypt($pass,CRYPT_STD_DES)."\n";
$htpasswd = fopen(".htpasswd", "a");
$r = fputs($htpasswd, $htpasswd_txt);
fclose($htpasswd);

the .htaccess looks like:
toto:1$5AVXvgnuw2.

Obviously they are different because they don't use the same seed to crypt.

Do you have any idea?
jchibbra
Forum Newbie
Posts: 11
Joined: Wed Apr 30, 2003 5:48 pm

Post by jchibbra »

I have only 1 thing to say:

@#$$%$#@%$#@ Windows.

because it works now. I restarted my computer and it works.
I really don't understand because every time I try with each of them (htpasswd and my function) I took all the precaution like closing the IE and reopen a new one.
And now it works.

I am really sorry if you wasted some times. :oops:

windows ?ucksssssssssss :)
Post Reply