Skip to content

Instantly share code, notes, and snippets.

@saghul
Created February 11, 2011 09:15
Show Gist options
  • Select an option

  • Save saghul/822112 to your computer and use it in GitHub Desktop.

Select an option

Save saghul/822112 to your computer and use it in GitHub Desktop.
Calculate response hash to HTTP digest authentication challenge
from hashlib import md5
# Calculate response hash to authentication challenge
def calc_auth_response(username, password, realm, nonce, digest_uri, method):
ha1 = md5('%s:%s:%s' % (username, realm, password)).hexdigest()
ha2 = md5('%s:%s' % (method, digest_uri)).hexdigest()
response = md5('%s:%s:%s' % (ha1, nonce, ha2)).hexdigest()
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment