ASP Fromwork中的修改密码和重置密码
protected void ChangePassword_Click(object sender, EventArgs e) { if (IsValid) { UserManager manager = new UserManager(); string UserID = User.Identity.GetUserId(); //IdentityResult result = manager.ChangePassword(UserID, CurrentPassword.Text, NewPassword.Text);//修改密码 var provider = new DpapiDataProtectionProvider("SampleAppName"); manager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(provider.Create("SampleTokenName"));// string token = manager.GeneratePasswordResetToken(UserID); IdentityResult result =manager.ResetPassword(UserID, token, NewPassword.Text); //重设密码 if (result.Succeeded) { var user = manager.FindById(User.Identity.GetUserId()); IdentityHelper.SignIn(manager, user, isPersistent: false); Response.Redirect("~/Account/Manage?m=ChangePwdSuccess"); } else { AddErrors(result); } } }
转载请注明出处:https://www.cnblogs.com/lei-zi/