Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6781607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:38:39+00:00 2026-05-26T16:38:39+00:00

I wrote a class to authenticate a user using HTTP Authentication the Digest way.

  • 0

I wrote a class to authenticate a user using HTTP Authentication the Digest way. I read a few articles and I got it working. Now, I would like to let it make use of Md5 passwords, but I can’t seem to get it working, this is the function authenticating the users.

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;

        }

    }

}

}

So imagine the $usr_password=”test” will be $usr_password=md5(“test”);

How do I compare passwords then?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:38:40+00:00Added an answer on May 26, 2026 at 4:38 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(1) is this way : http://code.google.com/intl/en/appengine/articles/djangoforms.html (2) is write by self : #/usr/bin/env python2.5
Using C#, I need a class called User that has a username, password, active
Here is a related manager I wrote: class PortfolioItemManager(models.Manager): use_for_related_fields = True def extended(self):
Okay, so i have this code i wrote: class Connection { public static StreamWriter
I recently wrote a class for an assignment in which I had to store
I wrote the following class for producing monitoring output within an extra window. Unfortunately
I wrote an abstraction class for a math object, and defined all of the
Here's a Django model class I wrote. This class gets a keyerror when I
I'm getting some really wierd linking errors from a class I wrote. I am
I wrote a managed C++ class that has the following function: void EndPointsMappingWrapper::GetLastError(char* strErrorMessage)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.