public ActionResult ResetPassword(ForgotUserNameOrPassword forgotUserNameOrPassword) { if (ModelState.IsValid) { var user = db.Users.Where(e => e.Email == forgotUserNameOrPassword.Email).FirstOrDefault(); if (user != null) { string newPassword = Guid.NewGuid().ToString().Split('-')[4]; user.PW = Convert.ToBase64String( new System.Security.Cryptography.SHA1CryptoServiceProvider().ComputeHash( Encoding.ASCII.GetBytes(newPassword))); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); using (var mySmtp = new MySmtpClient()) { using (var message = new MyEmail(user.Email)) { message.Subject = "Crafty Loser Password resest notification"; message.Body = "New password is " + newPassword; mySmtp.Send(message); } } } else { ModelState.AddModelError("", "Email not found."); return View(forgotUserNameOrPassword); } } else { return View(forgotUserNameOrPassword); } return RedirectToAction("ResetPasswordNotification"); }
public ActionResult ForgotUsername(ForgotUserNameOrPassword forgotUserNameOrPassword) { if (ModelState.IsValid) { var user = db.Users.Where(e => e.Email == forgotUserNameOrPassword.Email).FirstOrDefault(); if (user != null) { using (var mySmtp = new MySmtpClient()) { using (var message = new MyEmail(user.Email)) { message.Subject = "Crafty Loser username request"; message.Body = "Username is " + user.UserName; mySmtp.Send(message); } } } else { ModelState.AddModelError("", "Email not found."); return View(forgotUserNameOrPassword); } } else { return View(forgotUserNameOrPassword); } return RedirectToAction("ForgotUsernameNotification"); }