I want to use the web storage for my login system which has about 24 pages. i am trying to use the HTML-5 web storage api for session value storage.
Here is what i have tried.
<div class="main">
<form id="form_id" method="post" name="myform">
<table>
<tr><td class="credentials-top">LoginID </td><td><input type="text" name="username" id="username" autofocus/></td></tr>
<tr><td class="credentials-top">Password </td><td><input type="password" name="password" id="password"/></td></tr>
</table>
<input type="button" value="Login" class="btn btn-warning" onclick="validate(),senduser()"/>
</form>
</div>
javascript:
function validate(){
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var role;
if (password == "vp"){
localStorage.setItem("role", "vp");
return false;
}
else if (password == "sales"){
localStorage.setItem("role", "sales");
return false;
}
else if (password == ""){
return false;
}
else{
window.location = "login-failed.html";
}
}
Here i want to set the value of role to vp or sales depending on password accecpted. and i want to use role value to check if the user is vp or sales, how can i do this?
role = localStorage.role? Will give you "vp" or "sales". As an aside, I'm not sure "vp" is a very secure password :)onclick="validate(); senduser();"(semicolon, not comma)