Skip to content

Commit

Permalink
Add password confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
ggorlen committed Jan 24, 2023
1 parent c80876e commit 178b027
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions creator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@

// Whatever array of bytes is in the password field
let password = new TextEncoder().encode(document.getElementById("password").value)
const passwordConfirm = new TextEncoder().encode(document.getElementById("password-confirm").value)

if (password.length == 0) {
throw new Error(`Empty password`)
}
else if (!bufEqual(password, passwordConfirm)) {
throw new Error(`Passwords must match`)
}

// Import password into a Key suitable for use with Cryptography APIs
let passwordKey = await window.crypto.subtle.importKey(
Expand Down Expand Up @@ -294,6 +298,20 @@
setMessage("Ready to encrypt 👍")
}

function bufEqual(a, b) {
if (a.length !== b.length) {
return false;
}

for (let i = 0; i < a.length; i++) {
if (a[i] !== b[i]) {
return false;
}
}

return true;
}

</script>
</head>
<body onload="init()">
Expand Down Expand Up @@ -324,6 +342,12 @@ <h1><a href="https://mprimi.github.io/portable-secret/">Portable Secret</a>: Sec
<input type="password" id="password" value="banana" required>
</label>
</div>
<div>
<label>
Confirm Password:<br>
<input type="password" id="password-confirm" value="banana" required>
</label>
</div>

<div>
Password hint:<br>
Expand Down

0 comments on commit 178b027

Please sign in to comment.