Solved

Manual Reset Users Password

Posted on 2013-11-19
3
379 Views
Last Modified: 2013-11-25
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

0
Comment
Question by:Shade22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39660365
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.
0
 

Accepted Solution

by:
Shade22 earned 0 total points
ID: 39662283
Sorry, I forgot to close this since I found my own solution.  The main issue was changing the user's password, secret question, and answer in one procedure.  With the need of current password to change the secret question and answer and the need of current password to reset or change the current password I had to use 2 providers.  Provider#1 is set to requiresQuestionAndAnswer="true" and provider#2 is set to requiresQuestionAndAnswer="false". I use provider#2 to reset the password, and then provider#1 to change the secret question and answer.

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

                MembershipUser u = Membership.GetUser(ddl_AllUsers.SelectedValue);
                MembershipUser mu = Membership.Providers["Provider#2"].GetUser(ddl_AllUsers.SelectedValue, true);
                string tempPswd = mu.ResetPassword();
                u.ChangePassword(tempPswd, tb_PWOverride.Text);
                Boolean result = u.ChangePasswordQuestionAndAnswer(tb_PWOverride.Text, tb_SecQuest.Text, tb_SecAns.Text);

                if (result)
                    Msg.Text = "Password Quesiton 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

0
 

Author Closing Comment

by:Shade22
ID: 39674047
It works.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question