【发布时间】:2020-02-21 05:44:02
【问题描述】:
我在我的 index.html 中为网页添加了这个脚本以保护密码,但它不能在同一页面工作
<script type="text/javascript">
var s ="";
while (s!= "12345678")
{
s=prompt("please enter your password");
if (s=="12345678")
{
window.location.href="http://localhost/know21feb"; //page to redirect if password entered is correct
}
else
{
alert("Incorrect password-Try again");
}
}
</script>
【问题讨论】:
-
这远非一种安全的密码验证方式。用户可以检查网页并获取密码,或者只是从原始 HTML 访问链接。用于安全验证用户的可用机制会因您向最终用户提供网页的方式而异。
-
使用服务器端编程语言(例如 PHP)会更安全,然后使用 XML HTTP 请求与 PHP 文件进行通信。
-
您可以在您的网络服务器上设置 HTTP 授权标头。这可能是最简单但安全的解决方案
标签: javascript html password-protection