J'ai écrit une classe pour authentifier un utilisateur en utilisant l'authentification HTTP la manière Digest. J'ai lu quelques articles et je l'ai fait fonctionner. Maintenant, je voudrais le laisser utiliser des mots de passe Md5, mais je n'arrive pas à le faire fonctionner, c'est la fonction d'authentification des utilisateurs.PHP Digest authentification avec MD5
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;
}
}
}
}
Alors, imaginez le usr_password de $ = "test" sera $ usr_password = md5 ("test");
Comment puis-je comparer les mots de passe?
Merci.
Je sais comment ça fonctionne, mais pas comment la comparaison des mots de passe est géré dans le processus d'authentification HTTP. – Roel