Copied to clipboard

Flag this post as spam?

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


  • Mathijs 27 posts 60 karma points
    Dec 09, 2010 @ 04:14
    Mathijs
    0

    Reset password after creating new user

    To be able to inform a user about it's newly created account, and provide the users it's password I thought of the following construction, which sets a new password which I afterwards send by e-mail. However.. one problem! The password never gets updated.. it stays the initally password set by the umbraco dialog.

    I use this code:

     Member.New += new Member.NewEventHandler(Member_AfterNew);

      void Member_AfterNew(Member sender, NewEventArgs e)

            { 

                String userName = sender.LoginName;

                String newPassword  = Membership.GeneratePassword(7,2);

                MembershipUser user = Membership.GetUser(userName);

                user.ChangePassword(user.ResetPassword(), newPassword);

     

      // ... send by email the newPassword

     

      }

    What could possibly go wrong?

     

  • Sascha Wolter 615 posts 1101 karma points
    Dec 09, 2010 @ 05:17
    Sascha Wolter
    0

    AFAIK you need to manually encode the password before saving it (if you are storing the passwords as hashes), like so:

    string password = Membership.GeneratePassword(10, 2);
    MemberShipHelper mh = new MemberShipHelper();
    string newPassword = mh.EncodePassword(password, MembershipPasswordFormat.Hashed);

    Don't know if that is your problem here though, but thought I'd mention it anyways. :)

    I have so far only used the depracated Member object to perform these operations, e.g.

    Member member = Member.GetMemberFromEmail(email);
    ...
    member.ChangePassword(newPassword);
    member.Save();

    , which seems to do the trick.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Dec 09, 2010 @ 10:05
    Matt Brailsford
    0

    Hey,

    You shouldn't need to encode the password yourself, as this is built into the Member entity whenever you use the Password field setter (it auto looks up the configuraed hash method for the Member MembershipProvider).

    I think the only thing you need to do extra (as shown in Saschas post) is to call

    member.save()

    After you rest the password. You may also want to store the member.ResetPassword() in a variable before passing it to the ChangePassword method so that you can add it to your email.

    Many thanks

    Matt

  • Mathijs 27 posts 60 karma points
    Dec 09, 2010 @ 21:00
    Mathijs
    0

    Thanks for your replies guys! However none of them solves my problem. 

    • As far I understand from the Umbraco documentation the MembershipHelper is deprecated .
    • The MembershipUser does not contain  a save() method.. 

    I used the example from this page: http://our.umbraco.org/wiki/how-tos/membership-providers

    Related config info:

    <add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Another Type" passwordFormat="Hashed" />

    Anyone?

     

     

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Dec 09, 2010 @ 21:19
    Matt Brailsford
    0

    Hey,

    You're right that accessing the Member class is depeceiated, but I tend to find if you are doing anything more complex than simply creating a user, or authenticating a user, there isn't really a way round it. If you actually look at the membership providers, you'll see it actually uses the Member classes anyway, and I wouldn't imagin that these are going to be dropped before v5, so it should be pretty safe to use.

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft