Advertisement
Guest User

Untitled

a guest
Mar 7th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. [AllowAnonymous]
  2. public async Task<ViewResult> ResetAllPasswords()
  3. {
  4. // Get a list of all Users
  5. List<ApplicationUser> allUsers = await db.Users.ToListAsync();
  6. // NOTE: make sure this password complies with the password requirements set up in Identity.Config
  7. string newPassword = "YourNewPassword!";
  8. int passwordChangeSuccess = 0;
  9. int countUsers = 0;
  10. // Loop through the list of Users
  11. foreach (var user in allUsers)
  12. {
  13. // Get the User
  14. ApplicationUser thisUser = await UserManager.FindByNameAsync(user.UserName);
  15. // Generate a password reset token
  16. string token = await UserManager.GeneratePasswordResetTokenAsync(thisUser.Id);
  17. // Change the password, using the reset token
  18. IdentityResult result = await UserManager.ResetPasswordAsync(thisUser.Id, token, newPassword);
  19.  
  20. // Record results (extend to taste)
  21. if (result.Succeeded)
  22. {
  23. passwordChangeSuccess++;
  24. }
  25. countUsers++;
  26. }
  27.  
  28. ViewBag.CountUsers = countUsers;
  29. ViewBag.PasswordSuccess = passwordChangeSuccess;
  30.  
  31. return View();
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement