From 843800194246b69564548cd8428023169bb299d2 Mon Sep 17 00:00:00 2001 From: Mal Curtis Date: Sun, 11 Sep 2016 03:08:51 +1200 Subject: [PATCH] Fix TP-Link Archer C7 long passwords (#3225) * Fix tplink C7 long passwords Fixes an issue where passwords longer than 15 chars could not log in to Archer C7 routers. * Truncate in correct place * Add comment about TP-Link C7 pass truncation * Fix lint error * Truncate comment at 79 chars not 80 --- homeassistant/components/device_tracker/tplink.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/device_tracker/tplink.py b/homeassistant/components/device_tracker/tplink.py index 17beab02532..ad295099bf5 100755 --- a/homeassistant/components/device_tracker/tplink.py +++ b/homeassistant/components/device_tracker/tplink.py @@ -277,8 +277,10 @@ class Tplink4DeviceScanner(TplinkDeviceScanner): _LOGGER.info("Retrieving auth tokens...") url = 'http://{}/userRpm/LoginRpm.htm?Save=Save'.format(self.host) - # Generate md5 hash of password - password = hashlib.md5(self.password.encode('utf')).hexdigest() + # Generate md5 hash of password. The C7 appears to use the first 15 + # characters of the password only, so we truncate to remove additional + # characters from being hashed. + password = hashlib.md5(self.password.encode('utf')[:15]).hexdigest() credentials = '{}:{}'.format(self.username, password).encode('utf') # Encode the credentials to be sent as a cookie.