asp.net membership change password without knowing old one

后端 未结 10 1973
日久生厌
日久生厌 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:11

    Try to use SimpleMembershipProvider it's easier:

    var token = WebSecurity.GeneratePasswordResetToken("LoginOfUserToChange");
    WebSecurity.ResetPassword(token, "YourNewPassword");
    
    0 讨论(0)
  • 2020-12-24 05:12

    Use the password you want to set from textbox in place of 123456.

     MembershipUser user;     
     user = Membership.GetUser(userName,false);
     user.ChangePassword(user.ResetPassword(),"123456");
    
    0 讨论(0)
  • 2020-12-24 05:17
    string username = "UserName";
    string userpassword = "NewPassword";
    string resetpassword;
        
    MembershipUser mu = Membership.GetUser(username, false);
    
    if (mu == null){
        Response.Write("<script>alert('Invalid Username!')</script>"); 
    }
    
    else{
        resetpassword = mu.ResetPassword(username);
        if (resetpassword != null){
             if (mu.ChangePassword(resetpassword, userpassword)){
                 Response.Write("<script>alert('Password changed successfully!')</script>"); 
             }
        }
        else{
               Response.Write("<script>alert('Oh some error occurred!')</script>"); 
            }
        }
    
    0 讨论(0)
  • 2020-12-24 05:20
     string username = "username";
     string password = "newpassword";
     MembershipUser mu = Membership.GetUser(username);
     mu.ChangePassword(mu.ResetPassword(), password);
    
    0 讨论(0)
  • 2020-12-24 05:27

    Please note, all these mentioned solutions will only work if the RequiresQuestionAndAnswer property is set to false in Membership system configuration. If RequiresQuestionAndAnswer is true then the ResetPassword method needs to be passed the security answer, otherwise it will throw an exception.

    In case you need RequiresQuestionAndAnswer set to true, you can use this workaround

    0 讨论(0)
  • 2020-12-24 05:30

    You need to reset the user's password before changing it, and pass in the generated password to ChangePassword.

    string randompassword = membershipUser.ResetPassword();
    membershipUser.ChangePassword(randompassword , userWrapper.Password)
    

    or inline:

    membershipUser.ChangePassword(membershipUser.ResetPassword(), userWrapper.Password)
    
    0 讨论(0)
提交回复
热议问题