public bool IsEmailExist(string emailID) { using (WEBUIEntities dc = new WEBUIEntities()) { var v = dc.UserRegisters.Where(a => a.Email == emailID).FirstOrDefault(); return(v != null); } }
public ActionResult Registration(UserRegister user) { bool Status = false; string message = ""; // Model Validation if (ModelState.IsValid) { // //Email is already Exist var isExist = IsEmailExist(user.Email); if (isExist) { ModelState.AddModelError("Email Exist", "Email Address already exist"); return(View(user)); } #region Password Hashing user.Password = Crypto.Hash(user.Password); user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword); #endregion #region Save to Database using (WEBUIEntities dc = new WEBUIEntities()) { dc.UserRegisters.Add(user); dc.SaveChanges(); // SendVerificationLinkEmail(user.EmailID, user.ActivationCode.ToString()); message = "Registration Successfully done"; Status = true; } #endregion } else { message = "InValid Request"; } ViewBag.Message = message; ViewBag.Status = Status; //Generate Activation Code //Password Hashing //Save data to database //Send Email to user return(View(user)); }
public ActionResult LogIn(UserLogin login, string ReturnUrl) { string message = ""; ViewBag.Message = message; using (WEBUIEntities dc = new WEBUIEntities()) { var v = dc.UserRegisters.Where(a => a.Email == login.Email).FirstOrDefault(); if (v != null) { if (string.Compare(Crypto.Hash(login.Password), v.Password) == 0) { int timeout = login.RememerMe ? 525600 : 1; var ticket = new FormsAuthenticationTicket(login.Email, login.RememerMe, 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 = "Invalid Credential provided"; } } else { message = "Invalid Credential provided"; } } ViewBag.Message = message; return(View()); }