]> git.ardis.lu - static-encrypt/commitdiff
Add custom message on incorrect password
authorArdis Lu <ardisglu@gmail.com>
Sat, 1 Apr 2023 23:57:58 +0000 (16:57 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sat, 1 Apr 2023 23:57:58 +0000 (16:57 -0700)
template.html

index 71b4afd995b83d2f6d3bced1b72521af4142eff2..95dc4b76584bb75b532175dcce6db9fbf5a42ded 100644 (file)
 
   <div>SCRIPT INJECTION</div>
   <script>
+    const input = document.querySelector('input');
+
     document.querySelector('form').addEventListener('submit', async e => {
       e.preventDefault();
       const password = new FormData(e.target).get('password');
-      const newDocument = await decrypt(content, password);
-
-      document.open();
-      document.write(newDocument);
-      document.close();
+      try {
+        const newDocument = await decrypt(content, password);
+        document.open();
+        document.write(newDocument);
+        document.close();
+      }
+      catch {
+        input.setCustomValidity('Incorrect password.');
+        input.reportValidity();
+      }
     });
+
+    input.addEventListener('input', e => e.target.setCustomValidity(''));
   </script>
 </body>
 
This page took 0.044076 seconds and 4 git commands to generate.