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

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

问题描述

如何重置其他用户的管理员密码?

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

我尝试使用下面的代码

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天全站免登陆