Guest User

Guest User

  • Tech Writer
  • 611
  • 129.4k

remember me in mvc with jquery.

Mar 27 2020 7:13 AM
public ActionResult Login(string EmailId, string Password, bool RememberMe)
{
FanzdbEntities _db = new FanzdbEntities();
AdminMaster Obj_AdminMaster = new AdminMaster();
HttpCookie cookie = new HttpCookie("UserDetail");
try
{
//if (ModelState.IsValid == true)
//{
if (RememberMe == true)
{
cookie["FirstName"] = EmailId;
byte[] b = ASCIIEncoding.ASCII.GetBytes(Password);
String EncryptedPassword = Convert.ToBase64String(b);
cookie["Password"] = EncryptedPassword;
cookie.Expires = DateTime.Now.AddDays(1);
HttpContext.Response.Cookies.Add(cookie);
}
else
{
cookie.Expires = DateTime.Now.AddDays(-1);
HttpContext.Response.Cookies.Add(cookie);
}
$('#btnAdminLogin').click(function () {
if ($('#txtEmailId').val() == "" || $('#txtPassword').val() == "" || $('#lblRemeber').val()) {
alert("Please fill all required fields");
return false;
}
var RememberMe = $('#exampleCheck1').prop('checked');
if (RememberMe == true) {
$.ajax({
url: 'Login/Login',
type: 'Post',
dataType: 'json',
data: {
"EmailId": $('#txtEmailId').val(), "Password": $('#txtPassword').val(), "RememberMe": RememberMe
},
success: function (data) {
var status = data.status;
if (status == true) {
var url = "/UserManagement/AllUsers";
window.location.href = url;
}
else {
alert("wrong credentials");
return false;
}
},
failure: function (data) {
alert("Something went wrong");
}
});
}
else {
$.ajax({
url: 'Login/Login',
type: 'Post',
dataType: 'json',
data: { "EmailId": $('#txtEmailId').val(), "Password": $('#txtPassword').val(), "RememberMe": RememberMe },
success: function (data) {
var status = data.status;
if (status == true) {
var url = "/UserManagement/AllUsers";
window.location.href = url;
}
else {
alert("wrong credentials");
return false;
}
},
failure: function (data) {
alert("Something went wrong");
}
});
}
});
</script>
It's me remeber me code .with jqury it's working fine. I have set cookies value this code.
But i have face a problem I have reload a page and logout  button click fill text box with EmailId and Password .
I want to fill this text box . how to this task possible with mvc and jquery. 

Answers (1)