diff --git a/src/public/main.js b/src/public/main.js index fb0e024..c2cc9eb 100644 --- a/src/public/main.js +++ b/src/public/main.js @@ -14,9 +14,13 @@ $(function() { var $usernameInput = $('.usernameInput'); // Input for username var $messages = $('.messages'); // Messages area var $inputMessage = $('.inputMessage'); // Input message input box + var $key = $('#key'); var $chatPage = $('.chat.page'); // The chatroom page + var key = CryptoJS.SHA3(Math.random().toString(36).substring(7)).toString(); + $key.val(key); + // Prompt for setting a username var username; var connected = false; @@ -49,7 +53,7 @@ $(function() { } else { fs(window.TEMPORARY, 100, - log.bind(log, "!!WARNING!! : Your browser is not in incognito mode! : !!WARNING!!"), + log.bind(log, "WARNING: Your browser is not in incognito mode!"), log.bind(log, "Your browser is in incognito mode.")); } @@ -81,11 +85,11 @@ $(function() { } function encrypt(text) { - return CryptoJS.AES.encrypt(text, roomId).toString(); + return CryptoJS.AES.encrypt(text, $key.val()).toString(); } function decrypt(text) { - return CryptoJS.AES.decrypt(text, roomId).toString(CryptoJS.enc.Utf8); + return CryptoJS.AES.decrypt(text, $key.val()).toString(CryptoJS.enc.Utf8) || text; } // Log a message @@ -161,7 +165,9 @@ $(function() { } else { $messages.append($el); } - $messages[0].scrollTop = $messages[0].scrollHeight; + + $messages[0].scrollTop = $messages[0].scrollHeight; // minus 60 for key + console.log($messages[0]); } // Prevents input from having injected markup diff --git a/src/public/style.css b/src/public/style.css index 62cbe09..bfc8037 100644 --- a/src/public/style.css +++ b/src/public/style.css @@ -98,7 +98,7 @@ ul { font-size: 150%; } -.inputMessage { +.inputMessage, #key { font-size: 100%; } @@ -137,7 +137,7 @@ ul { /* Input */ -.inputMessage { +.inputMessage{ border: 10px solid #000; bottom: 0; height: 60px; @@ -148,3 +148,13 @@ ul { right: 0; width: 100%; } + +#key { + border: 10px solid #000; + height: 60px; + left: 0; + outline: none; + padding-left: 10px; + right: 0; + width: 100%; +} diff --git a/src/views/index.mustache b/src/views/index.mustache index 6fb465e..b3fb3a1 100644 --- a/src/views/index.mustache +++ b/src/views/index.mustache @@ -12,6 +12,7 @@