JQuery remembers the username and password for the next automatic login
- 2020-06-01 08:19:20
- OfStack
Jquery stores the username and password in cookie
You need to import jquery.js and jquery.cookie.js
<html>
<head>
<title>test cookie</title>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.cookie.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
if ($.cookie("rmbUser") == "true") {
$("#ck_rmbUser").attr("checked", true);
$("#txt_username").val($.cookie("username"));
$("#txt_password").val($.cookie("password"));
}
});
// Remember the username and password
function Save() {
if ($("#ck_rmbUser").attr("checked")) {
var str_username = $("#txt_username").val();
var str_password = $("#txt_password").val();
$.cookie("rmbUser", "true", { expires: 7 }); // storage 1 A belt 7 Days of cookie
$.cookie("username", str_username, { expires: 7 });
$.cookie("password", str_password, { expires: 7 });
}
else {
$.cookie("rmbUser", "false", { expire: -1 });
$.cookie("username", "", { expires: -1 });
$.cookie("password", "", { expires: -1 });
}
};
</script>
</head>
<body>
<div>
User name: <input type="text" id="txt_username"/><br />
Password: <input type="text" id="txt_password"/><br />
<input type="checkbox" id="ck_rmbUser"/> Remember your username and password <br />
<input type="submit" id="sub" value=" The login " onclick="Save()"/>
</div>
</body>
</html>