Skip to content

Commit

Permalink
Make basic authentication work for python 2 & python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
ikarus23 committed Nov 22, 2017
1 parent 7a9c7bc commit 3ac476f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions droopy
Expand Up @@ -118,9 +118,12 @@ def check_auth(method):
def decorated(self, *pargs):
"Reject if auth fails."
if self.auth:
# TODO: Between minor versions this handles str/bytes differently
received = self.get_case_insensitive_header('Authorization', None)
expected = 'Basic ' + base64.b64encode(self.auth)
if sys.version_info >= (3, 0):
expected = 'Basic ' + base64.b64encode(
self.auth.encode('utf-8')).decode('utf-8')
else:
expected = 'Basic ' + base64.b64encode(self.auth)
# TODO: Timing attack?
if received != expected:
self.send_response(401)
Expand Down

0 comments on commit 3ac476f

Please sign in to comment.