diff --git a/plexpy/api2.py b/plexpy/api2.py index b5c06e14..4ee867d5 100644 --- a/plexpy/api2.py +++ b/plexpy/api2.py @@ -20,6 +20,8 @@ from __future__ import unicode_literals from future.builtins import str from future.builtins import object +from hashing_passwords import check_hash + import hashlib import inspect import json @@ -609,9 +611,17 @@ General optional parameters: ``` """ data = None - apikey = hashlib.sha224(str(random.getrandbits(256))).hexdigest()[0:32] + apikey = hashlib.sha224(str(random.getrandbits(256)).encode('utf-8')).hexdigest()[0:32] if plexpy.CONFIG.HTTP_USERNAME and plexpy.CONFIG.HTTP_PASSWORD: - if username == plexpy.CONFIG.HTTP_USERNAME and password == plexpy.CONFIG.HTTP_PASSWORD: + authenticated = False + if plexpy.CONFIG.HTTP_HASHED_PASSWORD and \ + username == plexpy.CONFIG.HTTP_USERNAME and check_hash(password, plexpy.CONFIG.HTTP_PASSWORD): + authenticated = True + elif not plexpy.CONFIG.HTTP_HASHED_PASSWORD and \ + username == plexpy.CONFIG.HTTP_USERNAME and password == plexpy.CONFIG.HTTP_PASSWORD: + authenticated = True + + if authenticated: if plexpy.CONFIG.API_KEY: data = plexpy.CONFIG.API_KEY else: