Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [AllowAnonymous]
- public async Task<ViewResult> ResetAllPasswords()
- {
- // Get a list of all Users
- List<ApplicationUser> allUsers = await db.Users.ToListAsync();
- // NOTE: make sure this password complies with the password requirements set up in Identity.Config
- string newPassword = "YourNewPassword!";
- int passwordChangeSuccess = 0;
- int countUsers = 0;
- // Loop through the list of Users
- foreach (var user in allUsers)
- {
- // Get the User
- ApplicationUser thisUser = await UserManager.FindByNameAsync(user.UserName);
- // Generate a password reset token
- string token = await UserManager.GeneratePasswordResetTokenAsync(thisUser.Id);
- // Change the password, using the reset token
- IdentityResult result = await UserManager.ResetPasswordAsync(thisUser.Id, token, newPassword);
- // Record results (extend to taste)
- if (result.Succeeded)
- {
- passwordChangeSuccess++;
- }
- countUsers++;
- }
- ViewBag.CountUsers = countUsers;
- ViewBag.PasswordSuccess = passwordChangeSuccess;
- return View();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement