title: Array and objects as a database
body: <p>I'm making a login system!
  for storing data I put an array with objects to be like a database.
  When I check that username and password exist in the database everything works fine,but if i do another check for example if the username and password fields are filled then it doesn't work properly.
  when I add this check to any then when I type in an existing username and password then I get the "error username or password" message.</p>
  
  <pre><code>&lt;input type="text" id='username'&gt;
  &lt;input type="password" id='password'&gt;
  &lt;input type="submit" id="submitlogin" value="Login" onclick="login()"&gt;
  </code></pre>
  
  <pre><code>var database = [
          {
              username: "amr",
              password: "123",
          },
          {
              username: "asmr",
              password: "321",
          },
          {
              username: "amrik",
              password: "1234",
          }
  ]
  function login (){
  var user = document.getElementById('username').value;
  var pass = document.getElementById('password').value;
  for(var i = 0; i &lt; database.length; i++)
  {     if(user === "" &amp;&amp; pass === "")
        {
           alert("enter username and password");
           return;
        }
        if(user === database[i].username &amp;&amp; pass === database[i].password) {
          window.location.href = "index.html";
        } 
  }
      alert("error username or password");
      return;
  }
  </code></pre>