<?php
//class to read username / password from a .htpasswd file
class password{
 var $p_lines = array();      	
 var $p_pass  = array();    
 var $en_pass = "";
 var $username = "";
 	
   function password(){}  
	 
   function ReadPasswords($file)                   //^ 
   {                  
     $this->p_lines = file($file);
     foreach ($this->p_lines as $line_num => $line) 
     {
	     @list($name, $pass) = split(":", $line);
         $this->p_pass[trim($name)] = trim($pass);
     }
   }
   
   function checkUserExists($user)
   {
      return isset($this->p_pass[$user])? true : false;	   
   }
   
   function lookupPass($user,$password)
   {
	 if(isset($this->p_pass[$user]))
	 {
	 $salt = substr( $this->p_pass[$user] , 0 , 2 ); 
            $enc_pw = crypt( $password, $salt ); 
            if ($enc_pw == $this->p_pass[$user])
            {
	           return true;
            }
            else
            {
                return false;
            }
     }
     else
       return false;
   }
}
?>