From 260d205028d8f3af8ad8d337fc0f9aefd63490b5 Mon Sep 17 00:00:00 2001 From: 413j0 Date: Wed, 13 Dec 2017 10:39:55 -0500 Subject: [PATCH 1/2] simple way to add the highlight to the password field just a quick an dirty way to get the yellow highlight on the password field --- content/stanford-pwdhash.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/content/stanford-pwdhash.js b/content/stanford-pwdhash.js index c0943b0..130a81e 100644 --- a/content/stanford-pwdhash.js +++ b/content/stanford-pwdhash.js @@ -192,6 +192,7 @@ function SPH_PasswordProtector(field, monitor) { this.nextAvail = this.firstAvail; this.field = field; this.field.setAttribute("secure","yes"); + this.field.setAttribute("style","background-color:yellow;"); window.addEventListener("keydown", this, true); window.addEventListener("keyup", this, true); window.addEventListener("keypress", this, true); @@ -207,6 +208,7 @@ function SPH_PasswordProtector(field, monitor) { window.removeEventListener("blur", this, true); window.removeEventListener("focus", this, true); window.removeEventListener("submit", this, true); + this.field.setAttribute("style","background-color:white;"); monitor.protector = null; } } From c49e047eac45b64261f5c22000c4104a874e7ff8 Mon Sep 17 00:00:00 2001 From: 413j0 Date: Mon, 1 Apr 2019 07:50:53 -0500 Subject: [PATCH 2/2] Update stanford-pwdhash.js --- content/stanford-pwdhash.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/content/stanford-pwdhash.js b/content/stanford-pwdhash.js index 130a81e..879c545 100644 --- a/content/stanford-pwdhash.js +++ b/content/stanford-pwdhash.js @@ -46,14 +46,14 @@ var SPH_debug = true; */ function SPH_dump(msg) { if (SPH_debug) { - console.log("pwdhash: " + msg); + console.log("pwdhash: " + msg); } } ////////////////////////////////////////////////////////////////////////////// // Constants -const SPH_kPasswordKey = "DOM_VK_F2"; +const SPH_kPasswordKey = "F2"; const SPH_kPasswordPrefix = "@@"; const SPH_kMinimumPasswordSize = 5; // Our defense against focus stealing @@ -80,7 +80,7 @@ SPH_PasswordKeyMonitor.prototype = { handleEvent: function(evt) { // Detect Password Key - if (evt.keyCode == evt[SPH_kPasswordKey]) { + if (evt.key == SPH_kPasswordKey) { evt.stopPropagation(); // Don't let user JavaScript see this event evt.preventDefault(); // Do not let the character hit the page if (evt.type == "keydown") { @@ -91,11 +91,12 @@ SPH_PasswordKeyMonitor.prototype = { // Detect Password Prefix if (evt.type == "keypress") { - var lastChar = String.fromCharCode(evt.charCode); + var lastChar = evt.key; this.keystream.push(lastChar); - if (this.keystream.length > SPH_kPasswordPrefix.length) + if (this.keystream.length > SPH_kPasswordPrefix.length) { this.keystream.shift(); + } if (!this.protector && this.keystream.join('') == SPH_kPasswordPrefix) { @@ -192,7 +193,6 @@ function SPH_PasswordProtector(field, monitor) { this.nextAvail = this.firstAvail; this.field = field; this.field.setAttribute("secure","yes"); - this.field.setAttribute("style","background-color:yellow;"); window.addEventListener("keydown", this, true); window.addEventListener("keyup", this, true); window.addEventListener("keypress", this, true); @@ -208,7 +208,6 @@ function SPH_PasswordProtector(field, monitor) { window.removeEventListener("blur", this, true); window.removeEventListener("focus", this, true); window.removeEventListener("submit", this, true); - this.field.setAttribute("style","background-color:white;"); monitor.protector = null; } }