I'm currently using JavaScript to create a password checksum by utilizing the SubtleCrypto.digest()
function. This function produces the result as a promise
object, which is then fed into an inline function to convert the outcome to a text representation of the hexadecimal bytes. However, the issue arises when the inline text conversion function digToHex()
fails to update the hidden fields within the DOM before being submitted to the server via a POST request.
The function is triggered through an onclick()
event tied to the form's button. It captures the user's input password from the form and forwards it to the digestMsg()
function to create the hash.
It should be noted that while I acknowledge the security concerns surrounding SHA-1
, this is currently only a proof of concept.
Upon observing the output in the Chrome developer tools, across both the console and network tab, I noticed that the submitted values always end up as null. Even though the hash does seem to get generated by the digToHex()
function (as shown by the value of chk.value
in the console tab), the hidden fields don't get updated as expected. I've tried changing assignments and submitting the form inside and outside the digestMsg()
promise handler context as seen in the code snippet below.
... (Code Snippet) ...
Uncommenting either of the two submit()
lines only results in null values being received on the server, despite the correct values showing up in the console output of the Chrome developer tools. Further investigation into the network output tab of the developer tools confirms that only null values are being transmitted. Ideally, I should be seeing "opt"
with a value of 3
and chk1
showing the hash value.
Below is the HTML code that triggers the JavaScript functionalities:
... (HTML Snippet) ...
Following additional tests conducted by Marius, it was found that the code does work correctly on a static HTML page. Therefore, the issue seems to be linked to how the HTML is being dynamically loaded for each form. The HTML for the main (parent) page is appended below:
... (Parent HTML Snippet) ...