我試圖在客戶端散列我的密碼,然后再將它發送到我的服務器(Tomcat 服務器),當我點擊提交時,在將密碼值更新為哈希碼之前提交表單時我如何確保我的表單腳本執行后提交?或者有更好的方法嗎?
<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>
uj5u.com熱心網友回復:
在此程序后提交您的表格
<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
});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/373476.html
標籤:javascript html 公猫 网豆 散列
上一篇:如何從多個陣列列中添加一起價格?
