You can do something like this:
get
email
andpassword
as an input from the user.retrieve the user by email from the
localStorage
.if exists, compare
password
.
// email && password are <input /> fields
const email = document.getElementById("loginEmail");
const password = document.getElementById("loginPassword");
const btnSignin = document.getElementById("btn-signin");
function signIn() {
const users = JSON.parse(localStorage.getItem('users'));
const user = users.find(u => u.email === email.value);
if (user) {
if (user.password === password.value) {
alert("Wellcome " + user.firstName);
} else {
alert("Wrong password.");
}
} else {
alert("User deos not exist.");
}
}
btnSignin.addEventListener("click", signIn);
CLICK HERE to find out more related problems solutions.