var errCount = 0;
function check() {
if (errCount < 3) {
var name = document.getElementById("name").value;
var pass = document.getElementById("pass").value;
if (name === "帳號" && pass === "密碼") {
errCount = 0; // 成功重置
alert("登入成功");
document.forms[0].action = "shujubiao/";
document.forms[0].submit();
} else {
errCount++;
alert("用戶名或密碼連續錯誤 " + errCount + " 次");
}
}
if (errCount === 3) {
location.href = "禁止登入頁面.html"; // 鎖定跳轉
}
}
errCount 記錄連續失敗次數(頁面刷新會重置,若需持久化請用 localStorage)。location.href 跳轉,阻止後續嘗試。前端限制僅為使用者體驗,**真正防暴力破解必須在後端實施**(IP 限流、帳號鎖定、驗證碼)。