Updating a users password using ASP.NET Identity 1.0

I've inherited a WebSite which, is using ASP.NET Identity version 1.0 for user managment, and have a situation, where we quickly need to roll out some functionality to allow a user to reset their password. We fully, intend to migrate this site onto the latest and greatest, the MS have to offer, but for the time being, we just need this to work.

I'v therefore, decompiled the Identity dll, and have tried calling it as follows:

  protected async void ForgotPassword(object sender, EventArgs e)
            string password = Membership.GeneratePassword(12, 1);
            var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));

            ApplicationUser user = manager.FindById(User.Identity.GetUserId());
            await manager.AddPasswordAsync(User.Identity.GetUserId(), password);

            //Send out email.
            GlobalMethods.SendPasswordChangeNotification(user.UserName, user.Email, password);

Open in new window

I get me email, with the random password, but the physicall PasswordHash and SecurityStamp in the underlining table (AspNetUser), isn't  updated at all.

Can you please assist?
Wayne AthertonProduct Analyst Financial Messaging LondonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Randy DownsOWNERCommented:
Maybe this will help.

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

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.