Avatar of Shade22
Shade22
Flag for United States of America asked on

Manual Reset Users Password

I currently have a site where I administer users and their account.  On my Admin dashboard I want to be able to reset their user's password to whatever I type without knowing the users current password.  Below is my coding, I want to either be able to get the user's current password and then change it to whatever I enter in the tb_PWOverride textbox or if that isn't possible I want to reset their password, and get the hashed password and change it to whatever I type in the tb_PWOverride textbox.

the textbox's tb_SecQuest, and tb_SecAns are text boxs I am using to update the security question and answer.  That part of the procedure is at least working right now.

        protected void btn_profile_Update_Click(object sender, EventArgs args)
        {
            try
            {

                MembershipUser u = Membership.GetUser(ddl_AllUsers.SelectedValue);
                //string tempPswd = u.ResetPassword(); ------I would use this line only if I reset
                string oldPswd = u.GetPassword();
                u.ChangePassword(oldPswd, tb_PWOverride.Text);
                Boolean result = u.ChangePasswordQuestionAndAnswer(tb_PWOverride.Text, tb_SecQuest.Text, tb_SecAns.Text);

                if (result)
                    Msg.Text = "Password Question and Answer has been updated.";
                else
                    Msg.Text = "Password Question and Answer was not updated.";
            }
            catch (Exception )
            {
                Msg.Text = "Change Failed. Please re-enter your values and try again.";
            }
        }

    }
}

Open in new window

C#.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
Shade22

8/22/2022 - Mon
Carl Tawn

If you call ResetPassword() on the User object it should generate a new password and return it to you. You can then feed that into the ChangePassword() method to change it.
ASKER CERTIFIED SOLUTION
Shade22

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Shade22

ASKER
It works.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23