Jak zresetować hasło za pomocą UserManager of ASP.NET MVC 5

Zastanawiam się czy jest sposób na zresetowanie hasła za pomocą UserManager z ASP.NET MVC 5

Próbowałem tego z użytkownikiem, który ma już hasło, ale bez powodzenia. Jakieś wskazówki?

IdentityResult result = UserManager.AddPassword(forgotPasswordEvent.UserId.ToString(), model.ConfirmPassword);
if (result.Succeeded)
{
       //
}
else
{
        AddErrors(result);
}
Author: Academy of Programmer, 2014-03-19

7 answers

Jest tutaj ASP.NET hasło resetowania tożsamości

UserManager<IdentityUser> userManager = 
    new UserManager<IdentityUser>(new UserStore<IdentityUser>());

userManager.RemovePassword(userId);

userManager.AddPassword(userId, newPassword);
 82
Author: Academy of Programmer,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:10:29

Przypuszczam, że to jest nowsze, ale jest takie API w Identity 2.0:

IdentityResult result = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.Password);

Model.Kod jest generowany w następujący sposób i powinieneś wysłać go jako link w wiadomości e-mail, aby upewnić się, że użytkownik, który twierdzi, że chce zmienić hasło, jest Tym, który jest właścicielem adresu e-mail: {]}

string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
 25
Author: Yan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-09-13 22:03:00

Spróbuj użyć sklepu użytkownika:

 var user = UserManager.FindById(forgotPasswordEvent.UserId);

 UserStore<ApplicationUser> store = new UserStore<ApplicationUser>();
 store.SetPasswordHashAsync(user, uManager.PasswordHasher.HashPassword(model.ConfirmPassword));

Tożsamość jest fajna, ale wciąż brakuje jakiejś implementacji

UPDATE

Identity 2.0 jest już dostępny i ma o wiele więcej funkcji

 3
Author: Jonesopolis,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 11:54:50

Dodałem to do mojej klasy UserManager:

    public virtual async Task<IdentityResult> UpdatePassword(ApplicationUser user, string newPassword)
    {
        var passwordStore = Store as IUserPasswordStore<ApplicationUser, string>;

        if (passwordStore == null)
            throw new Exception("UserManager store does not implement IUserPasswordStore");

        var result = await base.UpdatePassword(passwordStore, user, newPassword);

        if (result.Succeeded)
            result = await base.UpdateAsync(user);

        return result;
    }
 2
Author: James White,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-10-25 17:42:41

Wypróbuj ten kod. działa idealnie:

    var userStore = new UserStore<IdentityUser>();

    var userManager = new UserManager<IdentityUser>(userStore);

    string userName= UserName.Text;

    var user =userManager.FindByName(userName);
    if (user.PasswordHash != null  )
    {
        userManager.RemovePassword(user.Id);
    }

    userManager.AddPassword(user.Id, newpassword);
 2
Author: Ganesh PMP,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-03-04 06:28:15

Istnieją rozszerzenia do zmiany hasła w przestrzeni nazw Microsoft.AspNet.Tożsamość.

Https://msdn.microsoft.com/en-us/library/dn497466 (v=vs.108). aspx

 1
Author: Marcel Melzig,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-30 07:11:24
var validPass= await userManager.PasswordValidator.ValidateAsync(txtPassword1.Text);
if(validPass.Succeeded)
{
    var user = userManager.FindByName(currentUser.LoginName);
    user.PasswordHash = userManager.PasswordHasher.HashPassword(txtPassword1.Text);
    var res= userManager.Update(user);
    if(res.Succeeded)
    {
        // change password has been succeeded
    }
}
 1
Author: Martin Staufcik,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-06-29 14:30:35