繁体   English   中英

当我在客户端 hash 我的密码时,我没有得到散列字符串,而是得到密码本身

[英]when I hash my password on the client side , I am not getting the hashed string instead getting the password itself

我正在尝试 hash 在客户端将我的密码发送到我的服务器(Tomcat 服务器)之前,当我单击提交时,在将密码的值更新为哈希码之前提交了表单我如何确保我的表单脚本执行后提交? 或者有没有更好的方法来 go?

<html>
<head>
    <title>TODO supply a title</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, 
initial-scale=1.0">
</head>
<body>
    <h1></h1>
    <form method="post" onsubmit="encrypt(event);" action="login" >
        <input type="text" name="user_id">
        <input type="password" name="password" id="pass">
        <button id="but1" type="submit">submit</button>
    </form>
    <script>
function encrypt(event){
//  event.preventDefault();//prevents from form getting auto submitted              
document.querySelector("body").style.color="red";             
sha512(document.getElementById("pass").value).then((x)=> 
{                
document.getElementById("pass").value=x;                   
document.querySelector("h1").innerHTML = x;
});
}


            function sha512(str) {
            return crypto.subtle.digest("SHA-512", new TextEncoder("utf- 
8").encode(str)).then(buf => {
            return Array.prototype.map.call(new Uint8Array(buf), x=> 
(('00'+x.toString(16)).slice(-2))).join('');
            });
            }
            sha512("my string for hashing").then(x => console.log(x)); 
    </script>
  </body>
</html>

完成后提交您的表格

 <form id="form1" method="post" onsubmit="encrypt(event);" action="login" >
        <input type="text" name="user_id">
        <input type="password" name="password" id="pass">
        <button id="but1" type="submit">submit</button>
    </form>


function encrypt(event) {
  event.preventDefault(); //prevents from form getting auto submitted
  document.querySelector("body").style.color = "red";
  sha512(document.getElementById("pass").value).then((x) => {
    document.getElementById("pass").value = x;
    document.querySelector("h1").innerHTML = x;
    document.getElementById("form1").submit(); // submitting the form
  });
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM