Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Cabbit

macrumors 68020
Original poster
Jan 30, 2006
2,128
1
Scotland
For a user login(this does sound daft i know) i want to compare the username in htpasswd with the username in my database in order to allow logins.

Does anyone know how to read the usernames in the htpasswd file for comparing them with my database. I was thinking it would be converting it to xml or something first.
 
Well this command line command will give you a list of user names.
Code:
cat .htpasswd | sed -e s'/^\([_a-z]*\).*$/\1/'
You could use that to go line by line and compare in the DB.
 
It ended up i had to add my cgi bin to the php base path and then building the contents of the file into an array splitting it by :

PHP:
$htfile = '/var/www/vhosts/mydomain.com/cgi-bin/8pewPo7kZ6gdEYArjS3s9GQhyNn5BFzu/password/.htpasswd'; 
$res = Array(); 
foreach(file($htfile) as $l) 
{ 
$array = explode(':',$l); 
$user = $array[0]; 
$pass = chop($array[1]); 
$res[$user] = $pass; 
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.