Home  >  Article  >  Backend Development  >  php digest authentication

php digest authentication

WBOY
WBOYOriginal
2016-07-29 09:15:151345browse

According to the description of ,

A1=MD5(::)

A2=MD5(:)

Final result: MD5(MD5(A1)::::MD5(A2))

Pay attention to the MD5(A1 in the above line ) and MD5(A2) are problematic. The browser implements MD5(A1::::A2)

$realm= 'saberyjs';
$password='0011';//This way to query the database is just for testing convenience;
if(!isset($_SERVER['PHP_AUTH_DIGEST']))
{
$n> header ("www-authenticate:Digest realm ='".$realm."',nonce='".$nonce."',algorithm='md5',qop='auth'");
header("HTTP/1.0 401 Unauthorization Required");
exit();
}
else
{
       //echo 'sset';
                                                                                 ult=parse_auth_digest($_SERVER['PHP_AUTH_DIGEST'] );
             //var_dump($result);
                                                                                               
                                           //echo 'The random number has expired'; md5',qop='auth'");
header("HTTP/1.0 401 Unauthorization Required");
exit();
t['username'].":". $result['realm'].":".$password);
//$A1=md5($result['username'].':'.$result['realm'].':'.$password ).':'.$result['nonce'].':'.$result['cnonce'];
$A2=md5($_SERVER['REQUEST_METHOD'].":".$result['uri' ]);
$degest=md5($A1.":".$result['nonce'].':'.$result['nc'].':'.$result['cnonce'].': '.$result['qop'].':'.$A2);
// var_dump($degest);
if($degest!=$result['response'])
;
               var_dump($result);
function parse_auth_digest($auth_digest)
{
$pairs=array();
preg_match_all('/(w+ )=['"]?([/a-z0-9A-Z.]+)['"]?/i',$auth_digest,$result,PREG_SET_ORDER);
foreach($result as $value)
$ pairs [$ value [1]] = $ value [2];
// var_dump ($ pairs);
return $ pairs;
}
?
The above has introduced PHP digest authentication, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn