Beshoy Wageh

Beshoy Wageh

  • NA
  • 33
  • 4.6k

This Code not check of email in database

Jan 17 2019 2:07 PM
public ActionResult Login(Log login, string ReturnUrl = "")
{
string message = "";
using (LoginContext dc = new LoginContext())
{
var v = dc.registers.Where(a => a.Email == login.EmailID).FirstOrDefault();
if (v != null)
{
#region Verify Password
if (!v.IsEmailVerified)
{
ViewBag.Message = "Please verify your email first";
return View();
}
#endregion
#region Verify Password
if (string.Compare(Crypto.Hash(login.Password), v.Password) == 0)
{
int timeout = login.RememberMe ? 525600 : 20; // 525600 min = 1 year
var ticket = new FormsAuthenticationTicket(login.EmailID, login.RememberMe, timeout);
string encrypted = FormsAuthentication.Encrypt(ticket);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
cookie.Expires = DateTime.Now.AddMinutes(timeout);
cookie.HttpOnly = true;
Response.Cookies.Add(cookie);
if (Url.IsLocalUrl(ReturnUrl))
{
return Redirect(ReturnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
message = " You Need To Register Now !!! ";
}
#endregion
}
else
{
message = " You Need To Register Now !!! ";
}
}
ViewBag.Message = message;
return View();
}

Answers (2)