From 23d5a494cdc4cff606e202941e45d0cc7e0460e1 Mon Sep 17 00:00:00 2001 From: ggorlen Date: Tue, 27 Dec 2022 18:14:31 -0800 Subject: [PATCH] Use password type for inputs --- creator/index.html | 31 ++++++++++++++++++++++++++++--- creator/secret-template.html | 2 +- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/creator/index.html b/creator/index.html index 77d7410..55f7413 100644 --- a/creator/index.html +++ b/creator/index.html @@ -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( @@ -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; + } + @@ -319,10 +337,17 @@

Portable Secret: Sec
- Password:
- + +
+
+
-
Password hint:
diff --git a/creator/secret-template.html b/creator/secret-template.html index dc36967..9fd815e 100644 --- a/creator/secret-template.html +++ b/creator/secret-template.html @@ -230,7 +230,7 @@

Password hint:

Password:

- +