Javascript 当用户名和密码在html中相等时如何创建登录页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11930253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 07:43:49  来源:igfitidea点击:

how to create a login page when username and password is equal in html

javascripthtml

提问by Abhinai

How do I create a login page that goes to the next screen if the password is correct?

如果密码正确,如何创建进入下一个屏幕的登录页面?

<html>
<p> Enter Username and Password </p>
<FORM action="file:///android_asset/www/Browse.html" method="post">
    <P>
    <LABEL for="firstname">Username </LABEL>
              <INPUT type="text" id="Username"><BR>
    <LABEL for="lastname">Password </LABEL>
              <INPUT type="text" id="Password"><BR>
        <INPUT type="submit" value="Send"> <INPUT type="reset">
    </P>
 </FORM>
</html>

回答by ygssoni

<html>
    <head>
        <title>Login page</title>
    </head>
    <body>
        <h1>Simple Login Page</h1>
        <form name="login">
            Username<input type="text" name="userid"/>
            Password<input type="password" name="pswrd"/>
            <input type="button" onclick="check(this.form)" value="Login"/>
            <input type="reset" value="Cancel"/>
        </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 == "myuserid" && form.pswrd.value == "mypswrd") {
                    window.open('target.html')/*opens the target page while Id & password matches*/
                }
                else {
                    alert("Error Password or Username")/*displays error message*/
                }
            }
        </script>
    </body>
</html>

回答by Günther Jena

Doing password checks on client side is unsafe especially when the password is hard coded.

在客户端进行密码检查是不安全的,尤其是在密码是硬编码的情况下。

The safest way is password checking on server side, but even then the password should not be transmitted plain text.

最安全的方法是在服务器端检查密码,但即使如此,密码也不应该以明文形式传输。

Checking the password client side is possible in a "secure way":

可以以“安全的方式”检查密码客户端:

  • The password needs to be hashed
  • The hashed password is used as part of a new url
  • 密码需要散列
  • 散列密码用作新网址的一部分

Say "abc" is your password so your md5 would be "900150983cd24fb0d6963f7d28e17f72" (consider salting!). Now build a url containing the hash (like http://yourdomain.com/90015...f72.html).

说“ABC”是你的密码,这样你的MD5将是“900150983cd24fb0d6963f7d28e17f72”(考虑腌制!)。现在构建一个包含哈希的 url(如http://yourdomain.com/90015...f72.html)。