如果密码正确,制作一个简单的HTML表单检查器重定向?

时间:2016-09-19 02:43:31

标签: html passwords plaintext

我不是在找任何安全的东西,密码在html文档中是纯文本,这纯粹是为了我测试。我想知道的是如何在下面的代码中包含一个检查密码是否正确的语句,如果有,则重定向到'win.html'。

    <!DOCTYPE html>
<html>
<form action="">
  <input name="username" id="username" type="text">
  <input name="pass" id="pass" type="password">
  <input type="submit" value="Submit">
</form> 
</html>

感谢。

1 个答案:

答案 0 :(得分:-1)

嘿,我有一段时间没有进行网页开发,但如果你不关心安全性,我就会尝试做你正在尝试的事情

<!DOCTYPE html>
<html>
<form>
<input name="username" id="username" type="text">
<input name="pass" id="pass" type="password">
<input type="button" value="Submit" onclick="myFunction()">
</form> 


<script>
function myFunction(){
  var user = document.getElementById("username").value;
  var pass = document.getElementById("pass").value;

if(user == "Admin" && pass == "Password"){
            window.location.href="win.html"
        alert("correct");
   }else{
    alert("Incorrect username or password");
    }
}
</script>
</html>

用户名是Admin Passowrd是密码

将按钮类型从提交更改为按钮,因为我认为它正在停止重定向