我编写了一个类来使用HTTP身份验证摘要方式对用户进行身份验证。我阅读了一些文章,并使其工作。现在,我想让它使用Md5密码,但我似乎无法得到它的工作,这是验证用户的功能。使用MD5进行PHP摘要式身份验证
public function authenticate() {
// In case the user is not logged in already.
if (empty($_SERVER['PHP_AUTH_DIGEST'])) {
// Return the headers.
$this->show_auth();
} else {
// Parse the given Digest-data.
$data = $this->parse_request($_SERVER['PHP_AUTH_DIGEST']);
// Check the data.
if (!$data) {
// Display an error message.
die($this->unauthorized);
} else {
// Based on the given information, generate the valid response.
$usr_password = "test";
// Generate the response partly.
$A1 = md5($data['username'].":".$this->get_realm().":".$usr_password);
$A2 = md5($_SERVER['REQUEST_METHOD'].":".$data['uri']);
// Generate the valid response.
$val_response = md5($A1.":".$data['nonce'].":".$data['nc'].":".$data['cnonce'].":".$data['qop'].":".$A2);
// Compare the valid response with the given response.
if ($data['response'] != $val_response) {
// Display the login again.
$this->show_auth();
} else {
// Return true.
return true;
}
}
}
}
所以可以想象$ usr_password = “测试” 将是$ usr_password = MD5( “测试”);
如何比较密码呢?
谢谢。
我知道如何工作的,只是没怎么密码的比较在HTTP认证过程的处理。 – Roel