English 中文(简体)
PHP Digest accreditation with MD5
原标题:PHP Digest authentication with MD5

我写了一门课程,以认证用户使用《吉大港山区行动计划》的《文摘》方式。 我读了几篇文章,我开始这样做。 现在,我要请它使用5号密码,但我似乎不能这样做,这是验证用户的功能。

public function authenticate() {

// In case the user is not logged in already.
if (empty($_SERVER[ PHP_AUTH_DIGEST ])) {

    // Return the headers.
    $this->show_auth();

iii 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);

    iii 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();

        iii else {

            // Return true.
            return true;

        iii

    iii

iii

iii

因此,假设票价“标价”为1美元/秒钟=md5(“测试”);

我如何比较密码?

感谢。

最佳回答

<功能,功能,为相同投入得出相同结果的单向方法。

因此,如果将<代码>$password1 to $password2而又不透露(直接比较)这两个文本,就应当将其斜体进行比较:

$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
}

是否足够清楚? 让我知道。

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签