public void ResetPassword(int AccountID) { Account account = accountContext.GetAccount(AccountID); string newPassword = Encrypter.Encrypt("ShoeShop01!", account.Login.Salt); string subject = "Recover password for Shoe Shop"; string message = "Dear " + account.Login.UserName + "," + Environment.NewLine + Environment.NewLine + "You have requested a new password." + Environment.NewLine + "Your new password is : ShoeShop01!" + Environment.NewLine + Environment.NewLine + "With kind regards," + Environment.NewLine + "Shoe Shop"; account.Login.HashedPassword = newPassword; accountContext.UpdateAccount(account); emailLogic.SendEmail(account.Email, subject, message); }
public ActionResult Login(AccountLoginModel model, string returnUrl) { // Валидация if ((model == null) || (model.LoginID == null)) { ModelState.AddModelError("", "Въведете потребител"); return(View()); } if (model.Password == null) { ModelState.AddModelError("", "Въведете парола"); return(View()); } AccountModel account = null; using (AccountContext context = new AccountContext()) { account = context.GetAccount(model); } if (account == null) { ModelState.AddModelError("", "Грешна парола или потребител"); return(View()); } HttpSession.UserID = account.ID; var authTicket = new FormsAuthenticationTicket( 1, // version account.LoginID, // user name DateTime.Now, // created DateTime.Now.AddMinutes(20), // expires model.RememberMe, // persistent? account.Roles // can be used to store roles ); string encryptedTicket = FormsAuthentication.Encrypt(authTicket); var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); System.Web.HttpContext.Current.Response.Cookies.Add(authCookie); return(RedirectToLocal(returnUrl)); }