Copied to clipboard

Flag this post as spam?

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


  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Feb 23, 2010 @ 17:44
    Warren Buckley
    1

    Forgotton Password reset password not working - Umbraco 4.0.2.1

    Hiya Guys,
    Firstly like to appologise if this question has been asked before, if it has just point me in the right direction please.

    OK I have an umbraco 4.0.2.1 site and I am setting up a role based protection members area on the front end site and the <asp:login> controls and such work lovely.

    However the default <asp:PasswordRecovery> control I had no luck due to password being hashed. As when changing the membership provider settings in the web.config I get a YSOD saying

    Provider cannot retrieve hashed password

    OK then I thought I would create a custom .NET usercontrol to reset the password and send out an email.

    With the code below it is definately resetting the password with a new password, however when i try to then login, the new password sent out doesn't work. What am I doing wrong?

    Appreciate your input guys.

    Thanks,
    Warren

    protected void btnRetrievePwd_Click(object sender, EventArgs e)
        {
            string newPassword = string.Empty;

            //Get user based on their login name (when not logged in)
            MembershipUser user = Membership.GetUser(Username.Text, false);

            if (user == null)
            {
                //User not found.......

                //Display message
                message.Text = "Username not found";
            }
            else
            {
                //Reset password
                newPassword = user.ResetPassword();

                //Need to email out the new password...

                string emailMessage = "Your new password is " + newPassword;

                //Send EMail
                sendEmail("[email protected]", user.Email, "Reset password for Telenor Objects", emailMessage);

                //Display message
                message.Text = "Email sent with new password";
            }
  • Tim 225 posts 690 karma points
    Feb 23, 2010 @ 17:48
    Tim
    0

    Hi Warren,

    I think this may be related to the double hashing bug:

    http://umbraco.codeplex.com/WorkItem/View.aspx?WorkItemId=23320

    I submitted a patch for this, which has been accepted into version 4.1.

    I think the only workaround at this stage is to turn off password hashing.

    Although I might double check that.

    T

     

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Feb 23, 2010 @ 18:01
    Warren Buckley
    0

    Cheers Tim :)
    Hmmm not sure if I can go bleeding edge with this client's site and go with the 4.1 beta 2 release.

    I'll run it past the guys at work and see what they have to say though.

    Warren

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Feb 23, 2010 @ 19:36
    Richard Soeteman
    1

    Hi Warren,

    Had the same last week. Change the line

    newPassword = user.ResetPassword();

    to

     newPassword = Membership

     

    .GeneratePassword(6,2)

    bit hard coded but 6 is the length of your password and the 2 the amount of nonAlphanumeric digits

    More info on msdn

    Cheers,

    Richard

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Feb 24, 2010 @ 10:14
    Warren Buckley
    0

    Hiya Richard,
    Did this definately work for you?

    As I have just tried this and I am getting the new password sent in the email, but it still doesnt work with the login.

    <add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Another Type" passwordFormat="Hashed" />
  • Richard Soeteman 4035 posts 12842 karma points MVP
    Feb 24, 2010 @ 12:15
    Richard Soeteman
    1

    Hi Warren,

    Was watching speedskating yesterday so I made a mistake. You need to assign the new password to the member also. I am using the umbraco member objects for this. I know this is not the prefered approach but when using the default member objects you can set the password . I've used the code below:

     

    string newPassword = Membership.GeneratePassword(6, 2);

     

    Member member = Member.GetMemberFromEmail([email protected]);

    member.Password = newPassword;

    member.Save();

    Hope it works for you,

    Richard

  • Ian Smedley 97 posts 192 karma points
    Mar 25, 2010 @ 14:51
    Ian Smedley
    3

    I've found this quite interesting, I originally (wrongly) assumed that to change a member's password, you would set set the password property, and it would work out the hashing or encryption, such as:

    m.ChangePassword("password");

    What I actually found was this just wrote the value straight into the database, and thus the user could not log on after changing the password, so, I found that using the helper functions, you could hash the password manually, this applies for members changing their password, creating new accounts, or an administrator having the ability to set a members password (outside of Umbraco's admin suite)

    In this example, 1 is the fictional member ID!

    m = new Member(1);
     MemberShipHelper mh = new MemberShipHelper();
     m.ChangePassword(mh.EncodePassword(txtPassword.Text, MembershipPasswordFormat.Hashed));

     

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Mar 26, 2010 @ 09:53
    Warren Buckley
    0

    Ian i totally forgot about this post, but this looks like a good solution to the problem.

    Warren

  • Sascha Wolter 615 posts 1101 karma points
    Aug 18, 2010 @ 12:37
    Sascha Wolter
    0

    Works using 4.0.4.2 as well.

    Thanks for that Ian! :)

     

  • Tom W 39 posts 96 karma points
    Aug 30, 2011 @ 16:19
    Tom W
    0

     

     string newpassword = GeneratePassword();
                member.Password = newpassword;
                member.Save();

    If you wish to set the password directly, without using the MembershipProvider, this works and correctly hashed the password (GeneratePassword just does a Guid.NewGuid().ToString().Replace("-", "").Substring(0, 6) - but this could be anything.)

     

Please Sign in or register to post replies

Write your reply to:

Draft