0

Hash of a string and check

Hello everyone.

I use SHA-256 algorithm to generate hash from strings. Hashing is generated correctly and the value is copied to the clipboard.

function sha256HashAndCopyToClipboard(string : text) do
    "// Google Icon";
    let xIcon := "<svg xmlns=""http://www.w3.org/2000/svg"" height=""48px"" viewBox=""0 -960 960 960"" width=""48px"" fill=""#EA3323""><path d=""M429-360h102l-25-145q20-9 32-26.5t12-38.5q0-29-20.5-49.5T480-640q-29 0-49.5 20.5T410-570q0 21 12 38.5t32 26.5l-25 145Zm51 279q-140-35-230-162.5T160-523v-238l320-120 320 120v238q0 152-90 279.5T480-81Zm0-62q115-38 187.5-143.5T740-523v-196l-260-98-260 98v196q0 131 72.5 236.5T480-143Zm0-337Z""/></svg>";
    "
    // Icon style";
    let xStyle := "<style>h3 {text-align: center;}</style><body><h3>" + xIcon + "</h3></body>";
    "
    // Generation of sha-256";
    dialog("Hash SHA-256 Generated", html(xStyle +
    "<script src='https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/crypto-js.min.js'></script>
    <script>
        function computeSHA256AndCopy(text) {
            var hash = CryptoJS.SHA256(text).toString(CryptoJS.enc.Hex);
            var el = document.createElement('textarea');
            el.value = hash;
            document.body.appendChild(el);
            el.select();
            document.execCommand('copy');
            document.body.removeChild(el);
        }
        computeSHA256AndCopy('" + string + "');
    </script>"), ["OK"]);
end;
sha256HashAndCopyToClipboard(text)

 

After that, with the same function I verify if the hash is correct.

function verifySHA256(input, hash) {
    var computedHash = CryptoJS.SHA256(input).toString(CryptoJS.enc.Hex);
    return computedHash === hash;
}

 

, is it possible to also copy the hash into a text field and likewise manipulate the boolean result of the last function by copying it into a ninox true/false field?

Thank you.

Fabio.

1 reply

null
    • Sviluppatore Ninox
    • Fabio
    • 1 mth ago
    • Reported - view

    I solved it with:

    database.update(record_Id, field_Id, data)

Content aside

  • Status Answered
  • 1 mth agoLast active
  • 1Replies
  • 48Views
  • 1 Following