Skip to content

Commit

Permalink
Changes remember me to only store username, changes default state to …
Browse files Browse the repository at this point in the history
…off (#207)

Makes remember me more secure by only storing username. This also changes the default position of the checkbox to unchecked, and has a line that will clear the saved password from anyone's computer who has previously used remember me.
  • Loading branch information
tektaxi authored Dec 15, 2020
1 parent e886a10 commit 37b630a
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions public/js/login.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Remember me - load username/password from localStorage
// Remember me - load username from localStorage
window.addEventListener("load", () => {
localStorage.removeItem("password");
if (localStorage.getItem("remember") === "true") {
document.getElementById("remember-me").setAttribute('checked', true);
}
else {
document.getElementById("remember-me").setAttribute('checked', false);
document.getElementById("remember-me").click();
}

if (localStorage.getItem("username") === null) {
Expand All @@ -14,29 +16,19 @@ window.addEventListener("load", () => {
document.getElementById("input-username").setAttribute(
'value', localStorage.getItem("username")
);
document.getElementById("input-password").setAttribute(
'value', localStorage.getItem("password")
);
}

if (localStorage.getItem("password") === null) {
localStorage.removeItem("password");
}
});

// Remember me - store username/password in localStorage
// Remember me - store username in localStorage
document.getElementById("login100-form-btn").addEventListener("click", () => {
const checkBox = document.getElementById("remember-me");
if (checkBox.checked) {
const username = document.getElementById("input-username").value;
const password = document.getElementById("input-password").value;
localStorage.setItem("username", username);
localStorage.setItem("password", password);
localStorage.setItem("remember", "true");
}
else {
localStorage.removeItem("username");
localStorage.removeItem("password");
localStorage.setItem("remember", "false");
}
});

0 comments on commit 37b630a

Please sign in to comment.