public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { string qq = model.Email; var user = await UserManager.FindByNameAsync(model.Email); if (user == null) { return(View("Error")); } string newpassword = GenerateRandomPassword(6); string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var result = await UserManager.ResetPasswordAsync(user.Id, code, newpassword); if (result.Succeeded) { await EmailSend.EMailFPassw(model.Email, newpassword); return(View("ForgotPasswordConfirmation")); } } return(View(model)); }
public ActionResult ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { AbzContext db = new AbzContext(); Usr user = db.Users.FirstOrDefault(u => u.Email == model.Email); if (user == null) { return(View("Error")); } string NewPassword = GenerateRandomPassword(6); user.Password = NewPassword; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); EmailSend.EMailFPassw(model.Email, NewPassword); return(View("ForgotPasswordConfirmation")); } return(View(model)); }