/// <summary>
/// 修改密码
/// </summary>
/// <param name="userId"></param>
/// <param name="oldPwd"></param>
/// <param name="pwd"></param>
/// <returns></returns>
[Authorize]
public async Task<string> UpdateUserPassWordBy(Guid userId, string oldPwd, string pwd)
{
var user = await _userManager.FindByIdAsync(userId.ToString());
var pwdBool = await _userManager.CheckPasswordAsync(user, oldPwd);
if (!pwdBool) return "原密码不正确";
if (string.IsNullOrEmpty(pwd)) return "新密码不能为空";
await _identityOptions.SetAsync();
await _userManager.RemovePasswordAsync(user);
await _userManager.AddPasswordAsync(user, pwd);
return "修改成功";
}
用到的构造函数如下
private readonly IdentityUserManager _userManager;
private readonly IOptions<IdentityOptions> _identityOptions;