More in this section
Forums / Developing with Sitefinity / Change Passord

Change Passord

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
6 posts, 0 answered
  1. Joseph
    Joseph avatar
    0 posts
    Registered:
    16 Jul 2013
    20 Sep 2016
    Link to this post

    I am failing on the save.   It says I am not authorized to manage users.....

     

    Web Form Code

            public static bool ChangePassword(string username, string newPassword, string oldPassword)
            {
                UserManager userManager = UserManager.GetManager(ProviderName);

                User user = userManager.GetUser(username);

                bool result = userManager.ChangePassword(user, oldPassword, newPassword);

                if (result)
                {
                    userManager.SaveChanges();
                }

                return result;
            }

     

    Custom Membership Provider Code

            public override bool ChangePassword(User user, string oldPassword, string newPassword)
            {
                var userManager = UserManager.GetManager("Default");

                return userManager.ChangePassword(user, oldPassword, newPassword);

                throw new NotSupportedException();
            }

  2. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    20 Sep 2016 in reply to Joseph
    Link to this post

    Hi Joseph.,

    This is the working example:

    public static bool ChangePassword(string username, string newPassword, string oldPassword)
           {
               UserManager userManager = UserManager.GetManager(ProviderName);
               userManager.Provider.SuppressSecurityChecks = true;
     
               User user = userManager.GetUser(username);
     
               bool result = userManager.ChangePassword(user, oldPassword, newPassword);
     
               if (result)
               {
     
                   userManager.Provider.SuppressSecurityChecks = false;
                   userManager.SaveChanges();
               }
     
               return result;
           }

     

  3. Joseph
    Joseph avatar
    0 posts
    Registered:
    16 Jul 2013
    20 Sep 2016 in reply to Victor Leontyev
    Link to this post

    This is my updated code.  It returns the user object with a new password.    I needed to set the Suppress Security Check to = true.

    However when the userManager.SaveChanges() runs it runs without error, but it doesn't update the database with new password.  

     

            public static bool ChangePassword(string username, string newPassword, string oldPassword)
            {

                UserManager userManager = UserManager.GetManager("CustomMembershipProvider");

                userManager.Provider.SuppressSecurityChecks = true;
                
                User user = userManager.GetUser(username);

                bool result = userManager.ChangePassword(user, oldPassword, newPassword);
                try
                {
                    if (result)
                    {
                        userManager.SaveChanges();
                    }

                }
                catch (Exception ex)
                {
                    string exxx = ex.ToString();
                }
                return result;
            }

     

     

  4. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    20 Sep 2016 in reply to Joseph
    Link to this post

    My snippet of code is working fine for me. I checked it recently. 

    Can you please create short screencast, to prove that problem exists

  5. Joseph
    Joseph avatar
    0 posts
    Registered:
    16 Jul 2013
    21 Sep 2016 in reply to Victor Leontyev
    Link to this post

    Link for video  https://youtu.be/pRbFgZxRv_E

    Thanks for your help Victor!!

  6. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    26 Sep 2016 in reply to Joseph
    Link to this post
    As I noticed, in your video you didnt call userManager.SaveChanges() after
6 posts, 0 answered