+ Post New Thread
Results 1 to 3 of 3
Coding Thread, resetting password in Coding and Web Development; Hi All, So i have been playing with a powershell to reset a domain user password. which worked perfectly. Now ...
  1. #1

    Join Date
    Apr 2012
    Location
    Harlow, Essex
    Posts
    12
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    resetting password

    Hi All,

    So i have been playing with a powershell to reset a domain user password. which worked perfectly.
    Now trying to create it in c# with visual studio (nicer for the other people who will need to change a password), but can seem to figure out where its going wrong.

    Any off you able to lay fresh eyes on it?

    private void button1_Click(object sender, EventArgs e)
    {
    string username = UserTxtbox.Text;
    string newpassword = PwdTxtbox.Text;
    {
    DirectoryEntry user = new DirectoryEntry(username);
    user.Invoke("SetPassword", new object[] { newpassword });
    user.Close();
    }
    }
    Here is the powershell version i have working

    $password = (ConvertTo-SecureString -AsPlainText "Passw0rd123" -Force)
    $credential = New-Object System.Management.Automation.PSCredential "domain.local\admin",$password

    $user = Read-Host "Type username:"
    $newpassword = Read-Host "Type password:" -AsSecureString

    Set-ADAccountPassword –Identity $user -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $newpassword –Force)

  2. #2

    matt40k's Avatar
    Join Date
    Jun 2008
    Location
    Ipswich
    Posts
    4,335
    Thank Post
    367
    Thanked 619 Times in 506 Posts
    Rep Power
    155
    Try:

    Code:
            private bool ResetUserPassword
            {
                get
                {
                    try
                    {
                        // Create an Instance of DirectoryEntry.
                        DirectoryEntry myDirectoryEntry = new DirectoryEntry("LDAP://domain.local");
                        myDirectoryEntry.Username = this.UserTxtbox.Text;
                        myDirectoryEntry.Password = this.PwdTxtbox.Text;
                    }
                    catch (Exception)
                    {
                        return false;
                    }
                    return true;
                }
            }

  3. #3

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,675
    Thank Post
    3,209
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    Not that it helps with the coding question but why re-invent the wheel when there is :

    BCX Password Reset by Burconix : Reset Student User Password Free Tool for Schools, Business and Education - Burconix

    Password Control by Wisesoft : WiseSoft - Password Control. Active Directory Password Reset Tool.

SHARE:
+ Post New Thread

Similar Threads

  1. apc powerchute buisness ed reset password
    By russdev in forum Windows
    Replies: 7
    Last Post: 8th November 2011, 12:35 PM
  2. Reset Password Ubuntu Server
    By richard_s in forum *nix
    Replies: 5
    Last Post: 9th December 2009, 10:27 AM
  3. Replies: 7
    Last Post: 13th July 2009, 04:35 PM
  4. Replies: 1
    Last Post: 10th July 2009, 09:34 AM
  5. Replies: 12
    Last Post: 12th September 2005, 10:47 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •