在UserManager中更改密码(Asp.Identity)c#

时间:2016-07-02 06:48:27

标签: c# asp.net-identity usermanager

请建议最佳做法是在Asp.Identity中通过UserManager更新数据库中的新密码

目前我正在使用以下方法更新密码。这还不够,或者我想用不同的方法?

ApplicationDbContext context = new ApplicationDbContext();
UserStore<ApplicationUser> store = new UserStore<ApplicationUser>(context);
UserManager<ApplicationUser> UserManager = new UserManager<ApplicationUser>(store);
String userId = User.Identity.GetUserId();//"<YourLogicAssignsRequestedUserId>";
String newPassword = "test@123"; //"<PasswordAsTypedByUser>";
String hashedNewPassword = UserManager.PasswordHasher.HashPassword(newPassword);
ApplicationUser cUser = await store.FindByIdAsync(userId);
**await store.SetPasswordHashAsync(cUser, hashedNewPassword);
await store.UpdateAsync(cUser);**

0 个答案:

没有答案