public ActionResult PassRecovery(PassRecoveryViewModel model) { try { var user = _userManager.GetUserByEmail(model.Email); if (user == null) { throw new Exception(Resource.EmailNotRegistered); } var rand = new Random(); var newPass = Convert.ToString(rand.Next(100000, 999999)); var salt = PasswordHashing.GenerateSaltValue(); var pass = PasswordHashing.HashPassword(newPass, salt); user.passwordSalt = salt; user.password = pass; _userManager.Update(user); _userManager.SendPassRecovery(user, newPass); return(RedirectToRoute("EndPassRecovery")); } catch (Exception e) { model.Error = e.Message; return(View(model)); } }
public ActionResult EditPassword(EditPasswordViewModel model, long id) { try { if (!ModelState.IsValid) { return(View(model)); } var user = _userManager.GetById(id); if (user.password != PasswordHashing.HashPassword (model.Password, user.passwordSalt)) { throw new Exception(Resource.WrongPassword); } var newSalt = PasswordHashing.GenerateSaltValue(); user.passwordSalt = newSalt; user.password = PasswordHashing.HashPassword(model.NewPassword, newSalt); _userManager.Update(user); return(RedirectToRoute("UserPage")); } catch (Exception e) { model.Error = e.Message; return(View(model)); } }
public ActionResult Registration(RegisterViewModel model) { try { var entity = Mapper.Map <RegisterViewModel, User>(model); var user = _userManager.GetUserByEmail(model.Email); if (user != null) { throw new Exception("лваолв"); } var salt = PasswordHashing.GenerateSaltValue(); var pass = PasswordHashing.HashPassword(entity.password, salt); entity.passwordSalt = salt; entity.password = pass; entity.photo = "/images/Account/account.jpg"; _userManager.Add(entity); entity.roles = new List <UserInRoles>() { new UserInRoles() { id_roles = 2, id_user = entity.id } }; _userManager.Update(entity); var url = Url.Action("ConfirmEmail", "Account", new { token = entity.id, email = entity.email }, Request.Url.Scheme); _userManager.SentConfirmMail(entity, url); return(RedirectToRoute("AfterRegistration")); } catch (Exception e) { model.Error = e.Message; return(View(model)); } }