'Want to do local storage with login details
Currently, I am trying to store the email and password that is entered. Below I have the HTML and JS code
let email = document.querySelector(".email");
let password = document.querySelector(".password");
//Storing users email and password
function store()
{
localStorage.setItem('email',email.value)
localStorage.setItem('password', password.value)
}
function checkLogin()
{
//get set stored data
let emailStored = localStorage.getItem('email')
let passwordStored = localStorage.getItem('password')
//data entered from login-form
let emailInput = document.querySelector('.email').value
let passwordInput = document.querySelector('.password').value
if(emailInput != emailStored)
{
let eError = document.querySelector(".email-error-message")
eError.innerHTML = "Please enter valid email address"
}
if(passwordInput != passwordStored)
{
let pError = document.querySelector(".password-error-message")
pError.innerHTML = "Please enter password associated with email address"
}
}
<div class="login-form">
<div class="sign-in">
<h1>Sign In</h1>
<form class="form">
<input class="email" type="email" placeholder="Email Address" required />
<div class="email-error-message"></div>
<input class="password" type="password" placeholder="Password" minlength="6" required />
<div class="password-error-message"></div>
<button class="submit">Sign In</button>
<div class="remember-me">
<input class="checkbox" type="checkbox" />
<span class="remember">Remember me</span>
<span class="need">Need help?</span>
</div>
</form>
<div class="facebook-signin">
<img src="images/facebook_social media_social_icon.png" alt="facebook logo" />
<span class="flogin">Login in with facebook</span>
</div>
<div class="newNetoflix">
<div class="newToNetflix">New to Netflix?</div>
<a class="sign-up" data-uia="login-signup-now">Sign up now.</a>
</div>
<div class="disclaimer">
<span class="protected">This page is protected by Google reCAPTCHA to ensure you're not a
bot. </span>
<button type="submit" class="learn-more">Learn More</button>
</div>
</div>
</div>
My end goal is the following:
- when the user inputs their email address and password it is saved
- when user clicks the check box of remember me it keeps their email address there, but not their password.
PS: I am aware there needs to be an event listener with the checkbox, saying that when the checkbox is checked keep email when the browser refreshes.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
