check value in if statement (javascript) from another html file

180 views Asked by At

I am trying to make a page that contains a login form. I got its coding from a website (someone had given that), well in the coding the username and password is given for compare (which can be seen by anyone, who opens the html codes), that's why i want that how the value of username and password can be compared in java-script from an external txt file or html file. Kindly see the coding in order to better understand my problem. In coding "ABC" and "123" are username and password.

<body>
  <h1 style="font-family:Comic Sans Ms;text-align="center";font-size:20pt;
color:#00FF00;>
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 = "ABC" && form.pswrd.value == "123")
          {
              window.open('target.html')/*opens the target page while Id & password matches*/
          }
          else
          {
              alert("Error Password or Username")/*displays error message*/
          }
      }
      </script>
  </body>
1

There are 1 answers

1
Remy Grandin On

Technicly, you can load by AJAX a txt/xml or json file and read the data from that.

However, I strongly recommend that you make the user/password check on the server side as if you do it in javascript, it won't be secure at all as anyone could read them in less than 5 seconds !!!