VIJAYA KUMAR
VIJAYA KUMAR

Reputation: 21

Mvc Core Change Password

How to change a password in mvc core using Entity Framework

i have tried this method But Its doesnot worked...

public login(UserManager<IdentityUser> userManager,
                            SignInManager<IdentityUser> signInManager,
                            IdentityUser user)
{
    _userManager = userManager;
    _signInManager = signInManager;
    _user = user;
}

public async Task<IdentityResult> ChangePassword(ChangePassword changePassword)
{
    var res = await _userManager.ChangePasswordAsync(_user,
                                               changePassword.OldPassword,
                                               changePassword.NewPassword);           
    return res;
}

Upvotes: 2

Views: 193

Answers (1)

Hamed Lohi
Hamed Lohi

Reputation: 621

I think you got the first parameter _user wrong

Modify as follows:

User user = await _userManager.FindByIdAsync(userId);
var res = await _userManager.ChangePasswordAsync(user, changePassword.OldPassword, changePassword.NewPassword);

return res;

Upvotes: 4

Related Questions