From b30beac2b5739f9d737d9764b4b552b2d478b6b9 Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 5 Feb 2017 16:58:13 +1300 Subject: [PATCH] obfuscate saved password when re-logging in --- client/dcwebui.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/client/dcwebui.js b/client/dcwebui.js index 09a53b5..1b2cd5e 100644 --- a/client/dcwebui.js +++ b/client/dcwebui.js @@ -3,6 +3,8 @@ "use strict"; +var SENTINEL_PASSWORD = "************"; + var $ = (document.querySelectorAll ? function(s) { var r = document.querySelectorAll(s); @@ -261,8 +263,6 @@ var userlist = { return $(".userlist")[0].children.length; }, 'setInfo': function(nick, props) { - console.log([nick, props]); - var baseClass = "user-" + b64(nick); var $el = $("." + baseClass); var prop_str = []; @@ -296,12 +296,23 @@ var submit = function() { if (hub_state === 0) { hub_state = 1; - persistence_set("login", str); + hub_last_nick = str.split(":", 2)[0]; - var name_parts = str.split(":", 2); - hub_last_nick = name_parts[0]; - - sock.emit('hello', {'nick' : hub_last_nick, 'pass' : name_parts.length >= 2 ? name_parts[1] : ''}); + var hub_pass = ""; + if (str.length > hub_last_nick.length) { + hub_pass = str.substr(hub_last_nick.length + 1); + } + if (hub_pass === SENTINEL_PASSWORD) { + // Probably not a real password. Attempt to load a better one from the saved state + var cache = persistence_get("login"); + if (cache.indexOf(":") != -1) { + hub_pass = cache.substr(cache.indexOf(":") + 1); + } + } + + persistence_set("login", hub_last_nick+":"+hub_pass); + + sock.emit('hello', {'nick' : hub_last_nick, 'pass' : hub_pass}); $("#chatbox").disabled = true; write("tab-main").system("Connecting..."); @@ -675,7 +686,11 @@ var persistence_get = function(key, fallback) { window.onload = function() { write("tab-main").system("Communicating with server..."); - $("#chatbox").value = persistence_get("login", ""); + var pre_login = persistence_get("login", ""); + if (pre_login.indexOf(":") !== -1) { + pre_login = pre_login.substr(0, pre_login.indexOf(":")) + ":" + SENTINEL_PASSWORD; + } + $("#chatbox").value = pre_login; show_joins = persistence_get("show_joins", false); document.title = DCWEBUI_CONF.title;