KumbiaPHP  beta2
Framework PHP
 Todo Estructuras de Datos Namespaces Archivos Funciones Variables Páginas
digest_auth.php
Ir a la documentación de este archivo.
1 <?php
30 class DigestAuth implements AuthInterface
31 {
32 
38  private $filename;
44  private $server;
50  private $username;
56  private $password;
62  private $realm;
68  private $resource;
69 
76  public function __construct($auth, $extra_args)
77  {
78  foreach (array('filename') as $param) {
79  if (isset($extra_args[$param])) {
80  $this->$param = $extra_args[$param];
81  } else {
82  throw new KumbiaException("Debe especificar el par�metro '$param' en los par�metros");
83  }
84  }
85  foreach (array('username', 'password') as $param) {
86  if (isset($extra_args[$param])) {
87  $this->$param = $extra_args[$param];
88  }
89  }
90  }
91 
96  public function get_identity()
97  {
98  $identity = array("username" => $this->username, "realm" => $this->realm);
99  return $identity;
100  }
101 
107  public function authenticate()
108  {
109  $this->resource = @fopen($this->filename, "r");
110  if ($this->resource === false) {
111  throw new KumbiaException("No existe o no se puede cargar el archivo '{$this->filename}'");
112  }
113 
114  $exists_user = false;
115  while (!feof($this->resource)) {
116  $line = fgets($this->resource);
117  $data = explode(":", $line);
118 
119  if ($data[0] == $this->username) {
120  if (trim($data[2]) == md5($this->password)) {
121  $this->realm = $data[1];
122  $exists_user = true;
123  break;
124  }
125  }
126  }
127  return $exists_user;
128  }
129 
135  public function set_params($extra_args)
136  {
137  foreach (array('filename', 'username', 'password') as $param) {
138  if (isset($extra_args[$param])) {
139  $this->$param = $extra_args[$param];
140  }
141  }
142  }
143 
148  public function __destruct()
149  {
150  @fclose($this->resource);
151  }
152 
153 }