Here is the code you are most likely looking for.
function ValidateByHtpwd($szLoginName, $szPassword)
{
if( is_file("/opt/apache/cgi-bin/.htpwd") )
{
$fPtr = fopen("/opt/apache/cgi-bin/.htpwd", "r");
if( !$fPtr )
return false;
/
File has opened ok, attempt to validate the user.
*/
while(!feof($fPtr))
{
$buffer = fgets($fPtr,128);
$index = strlen( $buffer );
$i=0;
$salt="";
while($i<$index)
{
if( $buffer[$i] == ':')
{
$salt = $buffer[$i+1].$buffer[$i+2]."";
break;
}
$i++;
}
$szBuffer = chop($buffer);
$szCryptString = crypt($szPassword, $salt);
$szCryptedLine = $szLoginName.":".$szCryptString;
if(!strcmp($szBuffer,$szCryptedLine))
return true;
}
fclose($fPtr);
}
return false;
}