Ejemplo n.º 1
0
        public async Task <ActionResult> ForgotPassword(ForgotViewModel model)
        {
            var user = this.modelContext
                       .Users
                       .FirstOrDefault(x => x.EmailConfirmed == true && x.Email == model.Email);

            if (user == null || !user.EmailConfirmed)
            {
                // Don't reveal that the user does not exist or is not confirmed
                return(View("ForgotPasswordConfirmation"));
            }
            user.resetPassToken = UniqueKeyUtil.GetUniqueKey(16);
            await EnviarMailRecuperoPassword(user);

            this.modelContext.SaveChanges();
            return(View("ForgotPasswordConfirmation"));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> RecoveryPassword(ResetPassViewModel model)
        {
            String userId      = Session["usuarioResetPassword"].ToString();
            String resetToken  = Session["tokenResetPassword"].ToString();
            String newPassword = model.NewPassword;

            ApplicationUser user = this.modelContext
                                   .Users
                                   .FirstOrDefault(x => x.Id == userId && x.resetPassToken == resetToken);

            if (user != null && resetToken.Length > 0)
            {
                ApplicationUser             cUser             = UserManager.FindById(userId);
                String                      hashedNewPassword = UserManager.PasswordHasher.HashPassword(newPassword);
                UserStore <ApplicationUser> store             = new UserStore <ApplicationUser>();
                await store.SetPasswordHashAsync(user, hashedNewPassword);

                user.resetPassToken = UniqueKeyUtil.GetUniqueKey(16);
                this.modelContext.SaveChanges();
            }

            return(View("~/Views/Account/Login.cshtml"));
        }