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

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>

This question is related to javascript html

The answer is


<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>

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).