KumbiaPHP beta2-dev
Framework PHP en español
digest_auth.php
Ir a la documentación de este archivo.
00001 <?php
00032 class DigestAuth implements AuthInterface {
00033 
00039         private $filename;
00040 
00046         private $server;
00047 
00053         private $username;
00054 
00060         private $password;
00061 
00067         private $realm;
00068 
00069 
00076         public function __construct($auth, $extra_args){
00077                 foreach(array('filename') as $param){
00078                         if(isset($extra_args[$param])){
00079                                 $this->$param = $extra_args[$param];
00080                         } else {
00081                                 throw new KumbiaException("Debe especificar el parámetro '$param' en los parámetros");
00082                         }
00083                 }
00084                 foreach(array('username', 'password') as $param){
00085                         if(isset($extra_args[$param])){
00086                                 $this->$param = $extra_args[$param];
00087                         }
00088                 }
00089         }
00090 
00095         public function get_identity(){
00096                 $identity = array("username" => $this->username, "realm" => $this->realm);
00097                 return $identity;
00098         }
00099 
00105         public function authenticate(){
00106                 $this->resource = @fopen($this->filename, "r");
00107                 if($this->resource===false){
00108                         throw new KumbiaException("No existe o no se puede cargar el archivo '{$this->filename}'");
00109                 }
00110 
00111                 $exists_user = false;
00112                 while(!feof($this->resource)){
00113                         $line = fgets($this->resource);
00114                         $data = explode(":", $line);
00115 
00116                         if($data[0]==$this->username){
00117                                 if(trim($data[2])==md5($this->password)){
00118                                         $this->realm = $data[1];
00119                                         $exists_user = true;
00120                                         break;
00121                                 }
00122                         }
00123                 }
00124                 return $exists_user;
00125         }
00126 
00127 
00133         public function set_params($extra_args){
00134                 foreach(array('filename', 'username', 'password') as $param){
00135                         if(isset($extra_args[$param])){
00136                                 $this->$param = $extra_args[$param];
00137                         }
00138                 }
00139         }
00140 
00141 
00146         public function __destruct(){
00147                 @fclose($this->resource);
00148         }
00149 
00150 }
 Todo Estructuras de Datos Namespaces Archivos Funciones Variables Enumeraciones