Example #1
0
        public ActionResult ResetPassword(string password, string passwordConfirm,
                                          string passwordToken, string userID)
        {

            var userStore = new UserStore<IdentityUser>();
            UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);
            var user = manager.FindById(userID);
            CreateTokenProvider(manager, PASSWORD_RESET);

            IdentityResult result = manager.ResetPassword(userID, passwordToken, password);
            if (result.Succeeded)
                ViewBag.Result = "The password has been reset.";
            else
                ViewBag.Result = "The password has not been reset.";
            return View();
        }
 public void EmailConfirmationToken()
 {
     var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(this._session));
     userManager.UserTokenProvider = new EmailTokenProvider<ApplicationUser, string>() { BodyFormat = "xxxx {0}", Subject = "Reset password" };
     userManager.Create(new ApplicationUser() { UserName = "test", Email = "[email protected]", EmailConfirmed = false }, "Welcome");
     var x = userManager.FindByEmail("[email protected]");
     string token = userManager.GeneratePasswordResetToken(x.Id);
     userManager.ResetPassword(x.Id, token, "Welcome!");
 }
        public ActionResult ResetPassword(string password, string passwordConfirm,
                                          string passwordToken, string userID)
        {
            //called from email link, receives token and allows user to change password
            var userStore = new UserStore<IdentityUser>();
            UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);
            var user = manager.FindById(userID);
            CreateToken ct = new CreateToken();
            CreateTokenProvider(manager, PASSWORD_RESET);

            IdentityResult result = manager.ResetPassword(userID, passwordToken, password);
            if (result.Succeeded)
                ViewBag.Result = "The password has been reset.";
            else
                ViewBag.Result = "The password has not been reset.";
            return View();
        }
        public ActionResult ResetPassword(ResetPassword resetPassword,
                                          string passwordToken, string userID)
        {
            if (ModelState.IsValid)
            {
                var userStore = new UserStore<IdentityUser>();
                UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);
                var user = manager.FindById(userID);
                CreateTokenProvider(manager, PASSWORD_RESET);

                IdentityResult result = manager.ResetPassword(userID, passwordToken, resetPassword.Password);
                if (result.Succeeded)
                {
                    TempData["Message"] = "The password has been reset. Please login in";
                    return RedirectToAction("Index");
                }
                else {
                    ViewBag.Message = "The password has not been reset.";
                }
            }
            else
            {
                ViewBag.Message = "Passworld reset failed. Please make sure password combine alphabet letter and numbers.";
            }

            return View();
        }