Create an admin account with a username and password that is seperate from the regular user accounts, only the admin should be able to see the Sales-graph, so when the admin logins, redirect them only to a sales.html page. You will need to hardcode this in your login script. Do not use window.location for redirection. Existing code: login.html Login User Name: User Pass: login.js function Login() { window.location.href = window.location.href.substring(0, window.location.href.lastIndexOf('/')) + "/Login.html" } function ResetPassword() { window.location.href = window.location.href.substring(0, window.location.href.lastIndexOf('/')) + "/resetpassword.html" } function LoginUser() { var userName = document.getElementById("txtUserName").value; var password = document.getElementById("txtPassword").value; var storedUserName = localStorage.getItem("UserName"); var storedPassword = localStorage.getItem("Password"); if (storedUserName && storedPassword) { if (userName.length > 0 && password.length > 0) { if (userName == storedUserName && password == storedPassword) { alert("Logged In"); } else { alert("username or password does not match and try again"); } } else { alert("username or password should not be blank"); } } else { alert("username or password does not match and try again"); } } function setUserNameAndPassOnStorage() { var userName = document.getElementById("txtUserName").value; var password = document.getElementById("txtPassword").value; if (userName.length > 0 && password.length > 0) { localStorage.setItem("UserName", userName); localStorage.setItem("Password", password); alert("Password Reset successfully"); } else { alert("username or password should not be blank"); } }
Create an admin account with a username and password that is seperate from the regular user accounts, only the admin should be able to see the Sales-graph, so when the admin logins, redirect them only to a sales.html page. You will need to hardcode this in your login script. Do not use window.location for redirection.
Existing code:
login.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Login</title>
<script src="./js/login.js"></script>
</head>
<body>
<div>
User Name: <input type="text" width="200" id="txtUserName" /><br />
User Pass: <input type="text" width="200" id="txtPassword" /><br />
<input type="button" value="Login" width="200" onclick="LoginUser()" />
<input type="button" value="Reset Password Page" width="200" onclick="ResetPassword()" />
</div>
</body>
</html>
login.js
function Login() {
window.location.href = window.location.href.substring(0, window.location.href.lastIndexOf('/')) + "/Login.html"
}
function ResetPassword() {
window.location.href = window.location.href.substring(0, window.location.href.lastIndexOf('/')) + "/resetpassword.html"
}
function LoginUser() {
var userName = document.getElementById("txtUserName").value;
var password = document.getElementById("txtPassword").value;
var storedUserName = localStorage.getItem("UserName");
var storedPassword = localStorage.getItem("Password");
if (storedUserName && storedPassword) {
if (userName.length > 0 && password.length > 0) {
if (userName == storedUserName && password == storedPassword) {
alert("Logged In");
} else {
alert("username or password does not match and try again");
}
} else {
alert("username or password should not be blank");
}
} else {
alert("username or password does not match and try again");
}
}
function setUserNameAndPassOnStorage() {
var userName = document.getElementById("txtUserName").value;
var password = document.getElementById("txtPassword").value;
if (userName.length > 0 && password.length > 0) {
localStorage.setItem("UserName", userName);
localStorage.setItem("Password", password);
alert("Password Reset successfully");
} else {
alert("username or password should not be blank");
}
}
Step by step
Solved in 2 steps