Better apikey generation

This commit is contained in:
JonnyWong16 2017-11-30 20:00:44 -08:00
parent 6cae12d467
commit 7e7693f206
2 changed files with 6 additions and 5 deletions

View file

@ -84,9 +84,6 @@ def delete_mobile_device(device_id=None):
def blacklist_logger():
devices = get_mobile_devices()
blacklist = []
for d in devices:
blacklist.append(d['device_token'])
blacklist = [d['device_token'] for d in devices]
logger._BLACKLIST_WORDS.extend(blacklist)

View file

@ -19,6 +19,7 @@ import os
import random
import shutil
import threading
import uuid
import cherrypy
from cherrypy.lib.static import serve_file, serve_download
@ -3489,7 +3490,10 @@ class WebInterface(object):
@cherrypy.tools.json_out()
@requireAuth(member_of("admin"))
def generate_api_key(self, device=None, **kwargs):
apikey = hashlib.sha224(str(random.getrandbits(256))).hexdigest()[0:32]
apikey = ''
while not apikey or apikey == plexpy.CONFIG.API_KEY or mobile_app.get_mobile_device_by_token(device_token=apikey):
apikey = uuid.uuid4().hex
logger.info(u"New API key generated.")
logger._BLACKLIST_WORDS.append(apikey)