asp.net membership change password without knowing old one

后端 未结 10 2037
日久生厌
日久生厌 2020-12-24 04:48

Evaluting the method signature, it is required to know old password while changing it.

membershipUser.ChangePassword(userWrapper.OldPassword, userWrapper.Pas         


        
10条回答
  •  孤城傲影
    2020-12-24 05:32

    @Rob Church is right:

    The other answers here are correct but can leave the password in an unknown state.

    However, instead of his solution to do the validation by hand, I would try to change the password using the ResetPassword from token method and catch and show the error:

    var user = UserManager.FindByName(User.Identity.Name);
    string token = UserManager.GeneratePasswordResetToken(user.Id);
    var result = UserManager.ResetPassword(user.Id, token, model.Password);
    if (!result.Succeeded){
        // show error
    }
    

提交回复
热议问题