title: How to check if user exist in local storage
body: <p>I have this class project to build a user registration and login form that stores data using local storage. If a new user registers it stores their email address and password in localStorage which is working as expected.  </p>
  
  <p>But I am finding it difficult to compare data when a user that is not registered tries to login and when a user that is registered tries to login.</p>
  
  <p>If a user is registered and tries to login it should compare the input value with the stored data in localStorage and alert "login Successful" else "Not a registered user".</p>
  
  <p>I am using JavaScript to do this. 
  Any help is highly appreciated. </p>
  
  <p>Here is the code: </p>
  
  <pre><code>var userData;
  var usersr;
  var loginData;
  var usersl;
  // For user registration 
  const registerBtn = document.getElementById('register-btn')
  
  function UserRegistration() {
    userData = [{
      email: document.getElementById('register-email').value
    }, {
      password: document.getElementById('register-pass').value
    }];
    usersr = JSON.parse(localStorage.getItem('Users')) || [];
    usersr.push(userData);
    localStorage.setItem('Users', JSON.stringify(usersr));
    location.reload()
    console.log(userData)
  }
  // For user login 
  const loginBtn = document.getElementById('login-btn')
  
  function loginUser() {
    usersl = JSON.parse(localStorage.getItem('UsersLogin')) || [];
    loginData = [{
      loginEmail: document.getElementById('login-email').value
    }, {
      loginPass: document.getElementById('login-pass').value
    }];
    usersl.push(loginData)
    localStorage.setItem('UsersLogin', JSON.stringify(usersl))
    console.log(usersl)
    location.reload()
  }
  </code></pre>