Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python >= 3.2 hashlib is now expecting a byte stream #2

Closed
adulau opened this issue Aug 29, 2013 · 1 comment
Closed

Python >= 3.2 hashlib is now expecting a byte stream #2

adulau opened this issue Aug 29, 2013 · 1 comment
Assignees
Labels

Comments

@adulau
Copy link

adulau commented Aug 29, 2013

Hi,

I had some issues with Python 3.3 and hashlib as it seems that hashlib is now requiring a byte stream.

Let me know if this makes sense.

Cheers.

Diff below:

diff --git a/flask_httpauth.py b/flask_httpauth.py
index bdd8f95..55012a5 100644
--- a/flask_httpauth.py
+++ b/flask_httpauth.py
@@ -76,7 +76,7 @@ class HTTPBasicAuth(HTTPAuth):

 class HTTPDigestAuth(HTTPAuth):
     def get_nonce(self):
-        return md5(str(random())).hexdigest()
+        return md5(str(random()).encode('utf-8')).hexdigest()

     def authenticate_header(self):
         session["auth_nonce"] = self.get_nonce()
@@ -89,9 +89,9 @@ class HTTPDigestAuth(HTTPAuth):
         if auth.nonce != session.get("auth_nonce") or auth.opaque != session.get("auth_opaque"):
             return False
         a1 = auth.username + ":" + auth.realm + ":" + password
-        ha1 = md5(a1).hexdigest()
+        ha1 = md5(a1.encode('utf-8')).hexdigest()
         a2 = request.method + ":" + auth.uri
-        ha2 = md5(a2).hexdigest()
+        ha2 = md5(a2.encode('utf-8')).hexdigest()
         a3 = ha1 + ":" + auth.nonce + ":" + ha2
-        response = md5(a3).hexdigest()
+        response = md5(a3.encode('utf-8')).hexdigest()
         return response == auth.response
@ghost ghost assigned miguelgrinberg Aug 29, 2013
@miguelgrinberg
Copy link
Owner

Addressed in release 1.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants