Identity 2.0 管理员重置密码 [英] Identity 2.0 Reset password by Admin

查看:38
本文介绍了Identity 2.0 管理员重置密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以管理员身份为其他用户重置密码?

How can I reset password as a admin for other users?

我已经尝试使用下面的代码

I have tried using the code below

var code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
var result = await UserManager.ResetPasswordAsync(user.Id, code, vm.NewPassword);

在单步执行 GeneratePasswordResetTokenAsync 时,会调用控制器的 dispose 方法.

when stepping through GeneratePasswordResetTokenAsync, the dispose method of the controller is called.

有人能指教我吗?

推荐答案

您还可以扩展 UserManager 并公开不需要任何信息的显式 AdminChangePassword API.在 ApplicationUserManager 中扩展 UserManager 的类似内容应该可以工作:

You can also extend UserManager and expose an explicit AdminChangePassword API that doesn't require any information. Something like this in ApplicationUserManager which extends UserManager should work:

public IdentityResult ChangePasswordAdmin(string userId, string newPassword) {
     var user = FindById(userId);
     // validate password using PasswordValidator.Validate
     user.PasswordHash = PasswordHasher.HashPassword(newPassword);
     Update(user);
}

这篇关于Identity 2.0 管理员重置密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆