如何获取新ASP中用户的密码.网络身份识别系统?或者如何在不知道当前密码(用户忘记密码)的情况下重置?

推荐答案

In current release

假设您已经处理了重置忘记的密码的请求的验证,请使用以下代码作为示例代码步骤.

ApplicationDbContext =new ApplicationDbContext()
String userId = "<YourLogicAssignsRequestedUserId>";
String newPassword = "<PasswordAsTypedByUser>";
ApplicationUser cUser = UserManager.FindById(userId);
String hashedNewPassword = UserManager.PasswordHasher.HashPassword(newPassword);
UserStore<ApplicationUser> store = new UserStore<ApplicationUser>();            
store.SetPasswordHashAsync(cUser, hashedNewPassword);

In AspNet Nightly Build

该框架经过更新,可以与令牌一起处理伪造密码等请求.一旦发布,就需要简单的代码指导.

Update:

此次更新只是为了提供更清晰的步骤.

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);

Asp.net相关问答推荐

如何从 JavaScript 调用 C# 函数?

Linq 将复杂类型聚合成一个字符串

VS2012 中无法识别的标签前缀或设备过滤器asp

如何获取已构建、编码的 ViewState 的值?

asp.net、url 重写模块和 web.config

说服遗留应用程序 VB6 开发人员切换到 C#

Automapper - 映射器已初始化错误

有没有办法将 onclick 事件添加到 ASP.NET 标签服务器控件?

如何在没有实体框架的情况下使用 ASP.NET Identity 3.0

没有身份的 ASP.NET Core 2.0 承载身份验证

iOS 8 / Safari 8 不适用于 ASP.NET AJAX 扩展

Request.Params 和 Request.Form 什么时候不同?

AddDefaultTokenProviders:它是什么以及如何使用那些默认提供者?

如何将枚举类型绑定到 DropDownList?

用于验证的数据注释,至少一个必填字段?

使用 Asp.Net MVC 和 Web Api 配置 Ninject

如何验证 WebClient 请求?

ASP.NET 身份,需要强密码

为在 ASP.NET Web API 中使用 User.Identity.Name 的方法编写单元测试

您将如何将 ASP.Net MVC 嵌入到现有的网站项目中?