【发布时间】:2023-04-09 00:22:01
【问题描述】:
我有一个使用 HTML“编程”的网站,并且我找到了一个脚本 (JavaScript) 来获取网站维护时的密码。它目前只接受一个用户名和密码,是否可以让它接受多个? 这不是我的代码,我是在网上找到的,想添加。此项目纯粹用于教育目的。
**旁注,我没有大量经验,人们只是对这个问题投反对票并不会帮助我学习如何做到这一点。我是一名仍在学习这些语言的高中学生,唯一的学习方法就是在需要时寻求帮助。
<form name="login">
Username <input type="text" name="userid" />
Password <input type="password" name="pswrd" />
<input type="button" onclick="check(this.form)" value="Login" />
<button formaction="/index.html">Cancel</button>
</form>
<script language="javascript">
function check(form)/*function to check userid & password*/
{
/*the following code checkes whether the entered userid and password are matching*/
if(form.userid.value == "example-username" && form.pswrd.value == "example-password")
{
window.open("/mainpage.html")/*opens the target page while Id & password matches*/
}
else
{
alert("Error Password or Username")/*displays error message*/
}
}
</script>
【问题讨论】:
-
您是否知道此脚本完全不提供安全性?从字面上看,任何人都可以访问
/mainpage.html。只需查看页面源即可显示您的用户名和密码,并显示您尝试保护的文件的名称,以便可以直接加载。 -
是的,这只是为了让我学校里的白痴远离我,我主要是把它编程进去,因为我想学习如何做。
-
从长远来看,现在学习如何以错误的方式做事会让你付出代价。当你开始学习正确的做事方式时,你将不得不改掉坏习惯。你已经用 PHP 标记了这个问题。你在用 PHP 吗?
标签: javascript php html forms passwords