Re: Autenticación HTTP tipo Digest con PHP (¡urgente!)
| From: | Àngel Fenoy | Date: | Mon, 02 Dec 2002 15:55:59 +0000 |
| Subject: | Re: Autenticación HTTP tipo Digest con PHP (¡urgente!) | ||
| References: | 1 2 3 | Groups: | php.general.es |
| Request: | Send a blank email to general-es+get-29897@lists.php.net to get a copy of this message | ||
Dilluns Desembre 2 2002 16:39, Àngel Fenoy dixit:
> En la página del m*n**l referente a
> autenticación HTTP habia hace tiempo ...
> ...
> ...
¡Vaya por Dios! Se me han colado, junto con el comentario de Chris, algunos
otros comentarios que tenia guardados de la misma página y no tienen que ver
con autenticación digest. Ahora sí, este es el comentario de Chris, el resto
del mensaje anterior no tiene nada que ver con digest:
===================== aquí empieza ===========================
chris.minnoy at minds.be
09-Jan-2001 03:34
If you want to use HTTP Digest Authentication, these functions could help
(PHP4):
function getHTTPheaders() {
//* get all HTTP headers
$headers = getallheaders();
//* set all header tags to lowercase
while (list($header, $value) = each($headers)) {
$header = strtolower($header);
$headers2[$header] = $value;
}
return $headers2;
} // function
function analyseHeaders(&$headers) {
//* filter authorization information
$authorization_param = $headers['authorization'];
if ($authorization_param != '') {
$pos = strpos($authorization_param, ' ');
$delivered_auth_type = strtolower(substr($authorization_param, 0, $pos));
$authorization_params = substr($authorization_param, $pos+1);
//* analyse parameters
if ($delivered_auth_type == 'basic') {
list($loginname, $password) = explode(':',
base64_decode($authorization_params));
$params['authorization_type'] = 'basic';
$params['username'] = $loginname;
$params['password'] = $password;
} else if ($delivered_auth_type == 'digest') {
$params['authorization_type'] = 'digest';
$digest_params_tmp = explode(',', $authorization_params);
while ($digest_param = each($digest_params_tmp)) {
$tmp = trim($digest_param[1]);
list($tag, $value) = explode('=', $tmp);
if ($value[0] == '"') $value = substr($value, 1);
$len = strlen($value);
if ($value[$len-1] == '"') $value = substr($value, 0, $len-1);
$params[strtolower($tag)] = $value;
}
}
}
}
function requestDigestAuthentication($realm, $domain, $nonce, $opaque) {
header('WWW-Authenticate: Digest '.
"realm=\"$realm\", ".
"domain=\"$domain\", ".
"nonce=\"$nonce\", ".
"opaque=\"$opaque\", ".
'qop="auth,auth-int"');
} // function
...
$db_password = 'localpasswordoutofdatabase'; // is plain text, but other
system would be safer
$our_response = md5( md5("$username:$realm:$db_password").
":$db_nonce:$nc:$cnonce:$qop:".
md5("{$HTTP_SERVER_VARS['REQUEST_METHOD']}:{$HTTP_SERVER_VARS['REQUEST_URI']}"));
/*
Note: see ftp://ftp.isi.edu/in-notes/rfc2617.txt for more
info
Note: This code is just a sample, not a full working program !!!
*/
===================== aquí termina ===========================
Saludos
Àngel