From b4ba88b3e5e661609fc2d844660e1b8f235e9683 Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Sat, 8 Aug 2020 21:19:39 -0700 Subject: [PATCH] Fix get_apikey API command with a hashed password --- plexpy/api2.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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: