Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use .key instead of deprecated .keyCode, fix #10 #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions content/stanford-pwdhash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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") {
Expand All @@ -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) {
Expand Down