如何更新Identity 2.0中的注册用户密码 [英] how to update the registered user password in Identity 2.0
本文介绍了如何更新Identity 2.0中的注册用户密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
i想要更新注册用户密码。
Hi All,
i want to update the registered user password.
推荐答案
这只是一个粗略的版本,需要修复错误处理,什么不是,但这应该可以帮助你使用asp.net mvc中的身份管理重置密码。
This is just a rough version, needs to be spruced up with error handling and what not but this should help you reset passwords using identity management in asp.net mvc.
[HttpPost]
[AllowAnonymous]
public async Task<JsonResult> ChangePassword(ResetPasswordModel model)
{
var store = new UserStore<UsersTable>(new ApplicationDbContext());
var userManager = new UserManager<UsersTable>(store);
var newHashedPass = userManager.PasswordHasher.HashPassword(model.NewPassword);
var user = await store.FindByIdAsync(user.UserId);
await store.SetPasswordHashAsync(user, newHashedPass);
user.ResetPassId = Guid.NewGuid().ToString();
user.IsForcePwReset = false;
await store.UpdateAsync(user);
return Json(new{ data = "user password changed successfully"}, JsonRequestBehavior.AllowGet);
}
这篇关于如何更新Identity 2.0中的注册用户密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文