title: ASP.NET change AD password
body: <p>I know this is ugly and I know I should have it in try blocks I've just been tinkering trying to get it to work.  I'm missing something here and I would really appreciate some help figuring it out.  All I'm trying to do is to create a page with a text box for the login name as well as one for the old password and two for the new password.  To add more information the error I'm getting now is
  Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))
  when i try to invoke the ChangePassword</p>
  
  <pre><code>     Dim userid As String
      Dim password As String
      Dim login As String
      Dim check As String
      login = txtLogin.Text
      userid = txtLogin.Text
      password = txtOldPass.Text
      Dim entry As DirectoryEntry = New DirectoryEntry("LDAP://OU=PaidUsers,DC=LOCAL,DC=bb", "LOCAL\" &amp; userid, password)
  
      Dim obj As Object = entry.NativeObject
      Dim search As DirectorySearcher = New DirectorySearcher(entry)
      search.SearchScope = SearchScope.Subtree
      search.Filter = "(SAMAccountName=" &amp; login &amp; ")"
      Dim result As SearchResult = search.FindOne()
  
      check = CType(result.Properties("sAMAccountName")(0), String)
  
      If check = login Then
          If txtNewPass.Text = txtNewPass2.Text Then
              entry = result.GetDirectoryEntry()
              entry.Username = "LOCAL\" &amp; check
              entry.Password = txtOldPass.Text
              entry.AuthenticationType = AuthenticationTypes.Secure
              entry.Options.Referral = ReferralChasingOption.All
              entry.Invoke("ChangePassword", txtOldPass.Text, txtNewPass.Text)
              entry.CommitChanges()
              lblSuccess.Visible = True
  
          Else
              lblPasswdError.Visible = True
          End If
  
      Else
          lblError.Visible = True
      End If
  </code></pre>