Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bo Jacobsen 308 posts 1359 karma points
    14 days ago
    Bo Jacobsen
    0

    How to change member password from controller without the old password

    Hi all.

    Using Umbraco 7.15.3

    It will simply not letting me change a members password from a controller. The code execution without any exceptions, but no changes are made.

    I have tried this

    // In Surface controller
    var member = ApplicationContext.Current.Services.MemberService.GetById(1117);
    var changingPasswordModel = new Umbraco.Web.Models.ChangingPasswordModel()
    {
        OldPassword = null,
        NewPassword = "1234"
    };
    Members.ChangePassword(member.Username, changingPasswordModel, "UmbracoMembershipProvider");
    
    // Web.Config
    <add name = "UmbracoMembershipProvider" type="Umbraco.Web.Security.Providers.MembersMembershipProvider, Umbraco" minRequiredNonalphanumericCharacters="0" minRequiredPasswordLength="4" useLegacyEncoding="false" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Member" passwordFormat="Hashed" allowManuallyChangingPassword="true" />
    

    And this

    // In Surface controller
    var member = ApplicationContext.Current.Services.MemberService.GetById(1117);
    var changingPasswordModel = new Umbraco.Web.Models.ChangingPasswordModel()
    {
        OldPassword = null,
        NewPassword = "1234"
    };
    Members.ChangePassword(member.Username, changingPasswordModel, new Umbraco.Web.Security.Providers.MembersMembershipProvider(ApplicationContext.Current.Services.MemberService));
    
    // Web.Config
    <add name = "UmbracoMembershipProvider" type="Umbraco.Web.Security.Providers.MembersMembershipProvider, Umbraco" minRequiredNonalphanumericCharacters="0" minRequiredPasswordLength="4" useLegacyEncoding="false" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Member" passwordFormat="Hashed" allowManuallyChangingPassword="true" />
    

    And this

    // In Surface controller
    var member = ApplicationContext.Current.Services.MemberService.GetById(1117);
    var changingPasswordModel = new Umbraco.Web.Models.ChangingPasswordModel()
    {
        OldPassword = null,
        NewPassword = "1234",
        Reset = true
    };
    Members.ChangePassword(member.Username, changingPasswordModel, new Umbraco.Web.Security.Providers.MembersMembershipProvider(ApplicationContext.Current.Services.MemberService));
    
    // Web.Config
    <add name = "UmbracoMembershipProvider" type="Umbraco.Web.Security.Providers.MembersMembershipProvider, Umbraco" minRequiredNonalphanumericCharacters="0" minRequiredPasswordLength="4" useLegacyEncoding="false" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Member" passwordFormat="Hashed" allowManuallyChangingPassword="true" />
    

    Any ideas?

  • Bo Jacobsen 308 posts 1359 karma points
    1 week ago
    Bo Jacobsen
    101

    Okay i found out.

    I actuelly started with ApplicationContext.Current.Services.MemberService.SavePassword(member, "newPassword"); But that throwed an exception, then i went to to use Members.ChangePassword() method.

    After i changed allowManuallyChangingPassword to true in the web.config ApplicationContext.Current.Services.MemberService.SavePassword(member, "newPassword"); worked.

Please Sign in or register to post replies

Write your reply to:

Draft