-1

HTTP認証ダイジェスト方式を使用してユーザーを認証するクラスを作成しました。私はいくつかの記事を読んで、それを機能させました。さて、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;

        }

    }

}

}

したがって、$ usr_password="test"が$usr_password= md5( "test");になると想像してください。

次に、パスワードを比較するにはどうすればよいですか?

ありがとう。

4

1 に答える 1

0

The MD5 function is hashing function, one-directional method to produce the same result for the same input.

Thus, to compare $password1 to $password2 without revealing (comparing directly) both of them it should be enough to compare their hashes:

$hash1 = md5($password1); // hash for pass 1
$hash2 = md5($password2); // hash for pass 2

if ($hash1 === $hash2) {
    // here goes the code to support case of passwords being identical
} else {
    // here goes the code to support case of passwords not being identical
}

Is it clear enough? Let me know.

于 2011-11-03T09:19:01.037 に答える